NpsExcel help to read/create/overwrite excel spreadsheets.
Sample code for reading excel spreadsheet:
var excel = new NpsExcel(new NpsFile("myexcel.xls"),'r');
out.Info(excel.sheets);
excel.currentsheet=0;
out.Info(excel.sheetname);
out.Info(excel.rows);
out.Info(excel.columns);
out.Info(excel.GetCell(0,0));
out.Info(excel.GetString(1,1));
out.Info(excel.GetDouble(2,2));
out.Info(excel.GetDate(3,3));
out.Info(excel.GetBoolean(4,4));
excel.Close();
Sample code for creating excel spreadsheet:
var format1 = new NpsExcelFormat("","");
format1.SetFont("Arial",11,true,false,false,"black");
format1.SetAlignment("centre");
format1.SetVerticalAlignment("centre");
format1.SetBorder("all","thin");
format1.SetBackground("yellow");
format1.SetOrientation("horizon");
var excel = new NpsExcel(new NpsFile("new.xls"),'n');
excel.CreateSheet("My sheet",0);
excel.MergeCell(0,0,0,10);
excel.AddString(0,0,"TITLE TEST",format1);
excel.AddNumber(1,0,2.5,format1);
excel.AddDate(2,0,new Date(),format1);
excel.AddBoolean(3,0,true,format1);
excel.AddFormula(4,0,"5*2",format1);
excel.Write();
excel.Close();
Sample code for modifying excel spreadsheet:
var excel = new NpsExcel(new NpsFile("old.xls"),'rw');
excel.SetString(0,0,"MODIFY");
excel.SetNumber(1,0,3.8);
excel.SetString(1,0,"STRING");
excel.SetDate(2,0,new Date(2005,7,20));
excel.SetBoolean(3,0,false);
excel.SetFormula(4,0,"10*2");
excel.SetString(0,5,"STRING2");
excel.Write();
excel.Close();
| int |
sheets Get the number of sheets in this workbook, readonly. |
| int |
currentsheet Set the current sheet, start from 0 |
| String |
sheetname Get the current sheet name, readonly. |
| int |
rows Get the number of rows in current sheet, readonly |
| int |
columns Get the number of columns in current sheet, readonly |
| NpsExcel |
new(NpsFile file,String mode) Constructor. The file parameter indicates the 'file' to be opened in which way specified by 'mode' 1.mode=r, means readonly mode; 2.mode=n, means create/overwrite mode; 3.mode=rw, means open an existing file, if we failed to open the file or the file does not not exist, and an exception throwed. |
| void |
Open(NpsFile file,String mode) Open an excel file. The mode parameter is same as constructor. |
| String |
GetCell(int col, int row) Return the contents of this cell as a string |
| String |
GetString(int col, int row) Return the contents of this cell as a string |
| double |
GetDouble(int col, int row) Return the contents of this cell as a number |
| Date |
GetDate(int col, int row Return the contents of this cell as a date |
| boolean |
GetBoolean(int col, int row) Return the contents of this cell as a boolean |
| void |
CreateSheet(String name,int index) Create a new sheet |
| void |
SetName(String name) Sets the name of current sheet |
| void |
SetProtected(boolean b) Indicates whether or not this workbook is protected |
| void |
SetPassword(String pass) Sets the password for this sheet |
| void |
SetDefaultColumnWidth(int width) Sets the default column width |
| void |
SetDefaultRowHeight(int height) Sets the default row height |
| void |
SetRowView(int row,int height,boolean collapsed) Sets the height of the specified row, as well as its collapse status |
| void |
SetColumnView(int col,int width) Sets the view for this column |
| void |
InsertColumn(int col) Inserts a blank column into this spreadsheet. If the column is out of range of the columns in the sheet, then no action is taken |
| void |
InsertRow(int row) Inserts a blank row into this spreadsheet. If the row is out of range of the rows in the sheet, then no action is taken |
| void |
RemoveColumn(int col) Removes a column from this spreadsheet. If the column is out of range of the columns in the sheet, then no action is taken |
| void |
RemoveRow(int row) Removes a row from this spreadsheet. If the row is out of range of the columns in the sheet, then no action is taken |
| void |
MergeCell(int c1,int r1,int c2,int r2) Merges the specified cells |
| void |
AddString(int col,int row,String value,NpsExcelFormat format) Adds a cell to this sheet |
| void |
AddNumber(int col,int row,double value,NpsExcelFormat format) Adds a cell to this sheet |
| void |
AddDate(int col,int row,Object d,NpsExcelFormat format) Adds a cell to this sheet |
| void |
AddBoolean(int col,int row,boolean value,NpsExcelFormat format) Adds a cell to this sheet |
| void |
AddFormula(int col,int row,String formula,NpsExcelFormat format) Adds a cell to this sheet |
| void |
SetString(int col,int row,String value) Modify the cell value |
| void |
SetNumber(int col,int row,double value) Modify the cell value |
| void |
SetDate(int col,int row,Object d) Modify the cell value |
| void |
SetBoolean(int col,int row,boolean value) Modify the cell value |
| void |
SetFormula(int col,int row,String formula) Modify the cell value |
| void |
Write() Writes out the data held in this workbook to file in Excel format |
| void |
Close() Closes this workbook, and frees makes any memory allocated available for garbage collection |