当前位置: 首页 > 工具软件 > jExcel > 使用案例 >

jExcel api指引

唐修能
2023-12-01

前端操作Excel的api工具:https://github.com/SheetJS/sheetjs

 

下面是UI工具

jExcel quick reference

 

 

METHODS

MethodExample
getData: Get the full or partial table data
@Param boolan onlyHighlighedCells - Get only highlighted cells
myTable.getData([bool]);
getJson: Get the full or partial table data in JSON format
@Param boolan onlyHighlighedCells - Get only highlighted cells
myTable.getData([bool]);
getRowData: Get the data from one row by number
@Param integer rowNumber - Row number
myTable.getRowData([int]);
setRowData: Set the data from one row by number
@Param integer rowNumber - Row number
@param array rowData - Row data
myTable.setRowData([int], [array]);
getColumnData: Get the data from one column by number
@Param integer columnNumber - Column number
myTable.getColumnData([int]);
setColumnData: Set the data from one column by number
@Param integer columnNumber - Column number
@param array colData - Column data
myTable.setColumnData([int], [array]);
setData: Set the table data
@Param json newData - New json data, null will reload what is in memory.
myTable.setData([json]);
setMerge: Merge cells
@Param string columnName - Column name, such as A1.
@Param integer colspan - Number of columns
@Param integer rowspan - Number of rows
myTable.setMerge([string], [int], [int]);
getMerge: Get merged cells properties
@Param string columnName - Column name, such as A1.
myTable.getMerge([string]);
removeMerge: Destroy merged by column name
@Param string columnName - Column name, such as A1.
myTable.removeMerge([string]);
destroyMerged: Destroy all merged cellsmyTable.destroyMerge();
getCell: get current cell DOM
@Param string columnName - str compatible with excel, or as object.
myTable.getCell([string]);
getLabel: get current cell DOM innerHTML
@Param string columnName - str compatible with excel, or as object.
myTable.getLabel([string]);
getValue: get current cell value
@Param mixed cellIdent - str compatible with excel, or as object.
myTable.getValue([string]);
getValueFromCoords: get value from coords
@Param integer x
@Param integer y
myTable.getValueFromCoords([integer], [integer]);
setValue: change the cell value
@Param mixed cellIdent - str compatible with excel, or as object.
@Param string Value - new value for the cell
@Param bool force - update readonly columns
myTable.setValue([string], [string], [bool]);
setValueFromCoords: get value from coords
@Param integer x
@Param integer y
@Param string Value - new value for the cell
@Param bool force - update readonly columns
myTable.getValueFromCoords([integer], [integer], [string], [bool]);
resetSelection: Reset the table selection
@Param boolean executeBlur - execute the blur from the table
myTable.resetSelection([bool]);
updateSelection: select cells
@Param object startCell - cell object
@Param object endCell - cell object
@Param boolean ignoreEvents - ignore onselection event
myTable.updateSelection([cell], [cell], true);
updateSelectionFromCoords: select cells
@Param integer x1
@Param integer y1
@Param integer x2
@Param integer y2
myTable.updateSelectionFromCoords([integer], [integer], [integer], [integer]);
getWidth: get the current column width
@Param integer columnNumber - column number starting on zero
myTable.getWidth([integer]);
setWidth: change column width
@Param integer columnNumber - column number starting on zero
@Param string newColumnWidth - New column width
myTable.setWidth([integer], [integer]);
getHeight: get the current row height
@Param integer rowNumber - row number starting on zero
myTable.getHeight([integer]);
setHeight: change row height
@Param integer rowNumber - row number starting on zero
@Param string newRowHeight- New row height
myTable.setHeight([integer], [integer]);
getHeader: get the current header by column number
@Param integer columnNumber - Column number starting on zero
myTable.getHeader([integer]);
getHeaders: get all header titlesmyTable.getHeaders();
setHeader: change header by column
@Param integer columnNumber - column number starting on zero
@Param string columnTitle - New header title
myTable.setHeader([integer], [string]);
getStyle: get table or cell style
@Param mixed - cell identification or null for the whole table.
myTable.getStyle([string]));
setStyle: set cell(s) CSS style
@Param mixed - json with whole table style information or just one cell identification. Ex. A1.
@param k [optional]- CSS key
@param v [optional]- CSS value
myTable.setSyle([object], [string], [string]);
resetStyle: remove all style from a cell
@Param string columnName - Column name, example: A1, B3, etc
myTable.resetStyle([string]);
getComments: get cell comments
@Param mixed - cell identification or null for the whole table.
myTable.getComments([string]);
setComments: set cell comments
@Param cell - cell identification
@Param text - comments
myTable.setComments([string], [string]);
orderBy: reorder a column asc or desc
@Param integer columnNumber - column number starting on zero
@Param smallint sortType - One will order DESC, zero will order ASC, anything else will toggle the current order
myTable.orderBy([integer], [boolean]);
getConfig: get table definitionsmyTable.getConfig();
insertColumn: add a new column
@param mixed - num of columns to be added or data to be added in one single column
@param int columnNumber - number of columns to be created
@param boolean insertBefore
@param object properties - column properties
myTable.insertColumn([mixed], [integer], [boolean], [object]);
deleteColumn: remove column by number
@Param integer columnNumber - Which column should be excluded starting on zero
@param integer numOfColumns - number of columns to be excluded from the reference column
myTable.deleteColumn([integer], [integer]);
moveColumn: change the column position
@Param integer columnPosition
@Param integer newColumnPosition
myTable.moveColumn([integer], [integer]);
insertRow: add a new row
@Param mixed - number of blank lines to be insert or a single array with the data of the new row
@Param integer rowNumber - reference row number
@param boolean insertBefore
myTable.insertRow([mixed], [integer], [boolean]);
deleteRow: remove row by number
@Param integer rowNumber - Which row should be excluded starting on zero
@Param integer numOfRows - number of lines to be excluded
myTable.deleteRow([integer], [integer]);
moveRow: change the row position
@Param integer rowPosition
@Param integer newRowPosition
>myTable.moveRow([integer], [integer]);
download: get the current data as a CSV file
@Param bool - true to download parsed formulas.
myTable.download([bool]);
getMeta: get the table or cell meta information
@Param mixed - cell identification or null for the whole table.
myTable.getMeta([string]);
setMeta: set the table or cell meta information
@Param mixed - json with whole table meta information.
myTable.setMeta[mixed]);
fullscreen: Toogle table fullscreen mode
@Param boolan fullscreen - define fullscreen status as true or false
myTable.fullscreen([bool]);
getSelectedRows: Get the selected rows
@Param boolan asIds - Get the rowNumbers or row DOM elements
myTable.getSelectedRows([bool]);
getSelectedColumns: Get the selected columns
@Param boolan asIds - Get the colNumbers or row DOM elements
myTable.getSelectedColumns([bool]);
showColumn: show column by numbermyTable.showIndex([int]);
hideColumn: hide column by numbermyTable.hideColumn([int]);
showIndex: show column of index numbersmyTable.showIndex();
hideIndex: hide column of index numbersmyTable.hideIndex();
search: search in the table, only if directive is enabled during inialization.
@Param string - Search for word
myTable.search([string]);
resetSearch: reset search tablemyTable.resetSearch();
whichPage: Which page showing on jExcel - Valid only when pagination is true.myTable.whichPage();
page: Go to page number- Valid only when pagination is true.
@Param integer - Go to page number
myTable.page([integer]);
undo: Undo last changesmyTable.undo();
redo: Redo changesmyTable.redo();

Working example


 

2

 

EVENTS

Eventdescription
onloadThis method is called when the method setData
onbeforechangeBefore a column value is changed. NOTE: It is possible to overwrite the original value, by return a new value on this method. v3.4.0+
onchangeAfter a column value is changed.
onafterchangesAfter all changes are applied in the table.
onpasteAfter a paste action is performed in the javascript table.
onbeforepasteBefore the paste action is performed. Used to parse any input data, should return the data.
oninsertrowAfter a new row is inserted.
onbeforeinsertrowBefore a new row is inserted. You can cancel the insert event by returning false.
ondeleterowAfter a row is excluded.
onbeforedeleterowBefore a row is deleted. You can cancel the delete event by returning false.
oninsertcolumnAfter a new column is inserted.
onbeforeinsertcolumnBefore a new column is inserted. You can cancel the insert event by returning false.
ondeletecolumnAfter a column is excluded.
onbeforedeletecolumnBefore a column is excluded. You can cancel the insert event by returning false.
onmoverowAfter a row is moved to a new position.
onmovecolumnAfter a column is moved to a new position.
onresizerowAfter a change in row height.
onresizecolumnAfter a change in column width.
onselectionOn the selection is changed.
onsortAfter a colum is sorted.
onfocusOn table focus
onblurOn table blur
onmergeOn column merge
onchangeheaderOn header change
onundoOn undo is applied
onredoOn redo is applied
oneditionstartWhen a openEditor is called.
oneditionendWhen a closeEditor is called.
onchangestyleWhen a setStyle is called.
onchangemetaWhen a setMeta is called.
onchangepageWhen the page is changed.

Example on handling events on jExcel

 

3

 

INITIALIZATION

Parameterdescription
urlLoad a external json file from this URL: string
dataLoad this data into the javascript table: array
copyCompatibilityWhen is true copy and export will bring formula results, if false will bring formulas: boolean
rowsRow properties: height.: object
columnsColumn type, title, width, align, dropdown options, text wrapping, mask, etc.: object
defaultColWidthDefault width for a new column: integer
defaultColAlignDefault align for a new column: [center, left, right]
minSpareRowsMinimum number of spare rows: [integer]
minSpareColsMinimum number of spare cols: [integer]
minDimensionsMinimum table dimensions: [cols,rows]
allowExportAllow table export: bool
includeHeadersOnDownloadInclude header titles on download: bool
columnSortingAllow column sorting: bool
columnDragAllow column dragging: bool
columnResizeAllow column resizing: bool
rowResizeAllow row resizing: bool
rowDragAllow row dragging: bool
editableAllow table edition: bool
allowInsertRowAllow insert a new row: bool
allowManualInsertRowAllow user to insert a new row: bool
allowInsertColumnAllow insert a new column: bool
allowManualInsertColumnAllow user to create a new column: bool
allowDeleteRowAllow delete a row: bool
allowDeleteColumnAllow delete a column: bool
allowRenameColumnAllow rename a column: bool
allowCommentsAllow comments over the cells: bool
wordWrapGlobal text wrapping: bool
csvLoad a external CSV file from this URL: string
csvFileNameDefault filename for a download method: string
csvHeadersLoad header titles from the CSV file: bool
csvDelimiterDefault delimiter for the CSV file: string
selectionCopyAllow selection copy: bool
mergeCellsCells to be merged in the table innitialization: object
toolbarAdd custom toolbars: object
search: boolAllow search in the table
pagination: integerBreak the table by pages
paginationOptions: [array of numbers]Number of records per page: 25,50,75,100 for example.
fullscreen: bollFullscreen mode
lazyLoading: boolActivate the table lazyloading
loadingSpin: boolActivate the loading spin
tableOverflowAllow table overflow: bool
tableHeightForce the max height of the table: CSS String
tableWidthForce the max width of the table: CSS String
metaMeta information: object
styleCells style in the table innitialization: object
parseFormulasEnable execution of formulas inside the table
autoIncrementAuto increment actions when using the dragging corner
updateTableMethod to config custom script execution. NOTE: This does not work with lazyLoading, Pagination or Search options.
nestedHeadersDefine the nested headers, including title, colspan, etc: object
contextMenuContext menu content: function() { return customMenu }
text: objectAll messages to be customized

 

4

 

TRANSLATIONS

KeyDefault value
noRecordsFoundNo records found
showingPageShowing page {0} of {1} entries
showShow
entriesentries
insertANewColumnBeforeInsert a new column before
insertANewColumnAfterInsert a new column after
deleteSelectedColumnsDelete selected columns
renameThisColumnRename this column
orderAscendingOrder ascending
orderDescendingOrder descending
insertANewRowBeforeInsert a new row before
insertANewRowAfterInsert a new row after
deleteSelectedRowsDelete selected rows
editCommentsEdit comments
addCommentsAdd comments
commentsComments
clearCommentsClear comments
copyCopy...
pastePaste...
saveAsSave as...
aboutAbout
areYouSureToDeleteTheSelectedRowsAre you sure to delete the selected rows?
areYouSureToDeleteTheSelectedColumnsAre you sure to delete the selected columns?
thisActionWillDestroyAnyExistingMergedCellsAreYouSureThis action will destroy any existing merged cells. Are you sure?
thisActionWillClearYourSearchResultsAreYouSureThis action will clear your search results. Are you sure?
thereIsAConflictWithAnotherMergedCellThere is a conflict with another merged cell
invalidMergePropertiesInvalid merged properties
cellAlreadyMergedCell already merged
noCellsSelectedNo cells selected

Working example

 类似资料: