Package com.netlang.excel
Class ExcelDocument
java.lang.Object
com.netlang.excel.ExcelDocument
A simple implementation of an excel document that is based on POI to create, read and write XLS and XLSX documents.
This class do not work very well with big XLSX documents. If you are having performance issues please us XLSDocumentReader instead.
Example of modifying an existing Excel document:
This class do not work very well with big XLSX documents. If you are having performance issues please us XLSDocumentReader instead.
Example of modifying an existing Excel document:
ExcelDocument xls1 = new ExcelDocument(new File("C:\\Temp\\test.xls"),true);
ExcelSheet firstSheet=xls1.getFirstSheet();
firstSheet.set(1,1,"Hello");
xls1.close();
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionInitializes a newly createdExcelDocumentExcelDocument(NetlangFile file, boolean createIfNeeded) Creates or read Excel Document from local path.ExcelDocument(com.netlang.session.NetlangSession session, NetlangFile file, boolean createIfNeeded) Creates or read Excel Document from local path.ExcelDocument(com.netlang.session.NetlangSession session, String resourceid, String path, boolean createIfNeeded) Creates or read Excel Document from local path.ExcelDocument(File file, boolean createIfNeeded) Creates or read Excel Document from local path.ExcelDocument(String path, boolean createIfNeeded) Creates or read Excel Document from local path.ExcelDocument(String resourceid, String path, boolean createIfNeeded) Creates or read Excel Document from the specified resource id -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close this documentcreateSheet(String name) Create a new sheet.Returns the cell data.Get the first sheet in this excel document.intgetLastEmptyRow(String sheetName) Returns the last empty row from the sheet.intgetLastRow(String sheetName) Get the last row number from the sheet.getOrCreateSheet(String name) Get the sheet if exist otherwise create.Get sheet by name.org.apache.poi.ss.usermodel.WorkbookGet the workbookList all worksheets nameorg.apache.poi.ss.usermodel.Sheet[]List all work sheets.voidinsertRows(String sheetName, int insertAtRow, int numRowsToInsert) Insert new empty rows.voidopen()Open the file for read or write.com.intellus.sql.QuerySet cell data.voidremoveAllRows(String sheetName) Remove all rows from the sheet.voidremoveRows(String sheetName, int startRow, int endRow) Remove row from the sheet.voidremoveSheet(String sheetName) Remove sheet by name.byte[]save()Save this document to byte.voidsave(NetlangFile file) Save this document to the local file systemvoidSave this document to the resource idvoidSave this document to the local file systemvoidSave this document to the local file systemvoidSave this document to the resource idvoidSave the workbookvoidsaveWorkBook(String filename) intSearch for data.voidSet cell data.voidSet cell data.voidSet cell data.
-
Field Details
-
COMMAND_ADD
public static int COMMAND_ADD -
COMMAND_UPDATE
public static int COMMAND_UPDATE -
COMMAND_DELETE
public static int COMMAND_DELETE -
SET_KEYS
-
SET_DATA
-
-
Constructor Details
-
ExcelDocument
public ExcelDocument() throws com.net4z.APIExceptionInitializes a newly createdExcelDocument- Throws:
com.net4z.APIException
-
ExcelDocument
public ExcelDocument(String resourceid, String path, boolean createIfNeeded) throws com.net4z.APIException Creates or read Excel Document from the specified resource id- Parameters:
resourceid-path-createIfNeeded-- Throws:
com.net4z.APIException
-
ExcelDocument
Creates or read Excel Document from local path.- Parameters:
path-createIfNeeded-- Throws:
com.net4z.APIException
-
ExcelDocument
Creates or read Excel Document from local path.- Parameters:
file-createIfNeeded-- Throws:
com.net4z.APIException
-
ExcelDocument
Creates or read Excel Document from local path.- Parameters:
file-createIfNeeded-- Throws:
com.net4z.APIException
-
ExcelDocument
public ExcelDocument(com.netlang.session.NetlangSession session, NetlangFile file, boolean createIfNeeded) throws com.net4z.APIException Creates or read Excel Document from local path.- Parameters:
session-file-createIfNeeded-- Throws:
com.net4z.APIException
-
ExcelDocument
public ExcelDocument(com.netlang.session.NetlangSession session, String resourceid, String path, boolean createIfNeeded) throws com.net4z.APIException Creates or read Excel Document from local path.- Parameters:
session-resourceid-path-createIfNeeded-- Throws:
com.net4z.APIException
-
-
Method Details
-
open
public void open() throws com.net4z.APIExceptionOpen the file for read or write. Always called from the constructor.- Throws:
com.net4z.APIException
-
close
public void close() throws com.net4z.APIExceptionClose this document- Throws:
com.net4z.APIException
-
getWorksheets
List all work sheets.- Returns:
- Throws:
Exception
-
getWorksheetNames
List all worksheets name- Returns:
- Throws:
Exception
-
getWorkbook
public org.apache.poi.ss.usermodel.Workbook getWorkbook()Get the workbook- Returns:
-
getFirstSheet
Get the first sheet in this excel document.- Returns:
- Throws:
Exception
-
getSheet
Get sheet by name.- Parameters:
name-- Returns:
- Throws:
Exception
-
getOrCreateSheet
Get the sheet if exist otherwise create.- Parameters:
name-- Returns:
- Throws:
Exception
-
removeSheet
Remove sheet by name.- Parameters:
sheetName-- Throws:
Exception
-
createSheet
Create a new sheet.- Parameters:
name-- Returns:
- Throws:
Exception
-
save
Save this document to byte.- Returns:
- Throws:
Exception
-
save
Save this document to the local file system- Parameters:
path-- Throws:
com.net4z.APIException
-
save
Save this document to the local file system- Parameters:
file-- Throws:
com.net4z.APIException
-
save
Save this document to the local file system- Throws:
com.net4z.APIException
-
save
Save this document to the resource id- Parameters:
resourceid-filepath-- Throws:
com.net4z.APIException
-
save
public void save(com.netlang.session.NetlangSession session, String resourceid, String filepath) throws com.net4z.APIException Save this document to the resource id- Parameters:
session-resourceid-filepath-- Throws:
com.net4z.APIException
-
saveWorkBook
Save the workbook- Throws:
Exception
-
saveWorkBook
- Throws:
Exception
-
insertRows
Insert new empty rows.- Parameters:
sheetName-insertAtRow-numRowsToInsert-- Throws:
Exception
-
removeRows
Remove row from the sheet.- Parameters:
sheetName-startRow-endRow-- Throws:
Exception
-
removeAllRows
Remove all rows from the sheet.- Parameters:
sheetName-- Throws:
Exception
-
get
Returns the cell data.- Parameters:
sheetName-row-column-- Returns:
- Throws:
Exception
-
search
public int search(String sheetName, int startRow, String column, String data, boolean caseSensitive) throws Exception Search for data.- Parameters:
sheetName-startRow-column-data-caseSensitive-- Returns:
- Throws:
Exception
-
getLastRow
Get the last row number from the sheet.- Parameters:
sheetName-- Returns:
- Throws:
Exception
-
getLastEmptyRow
Returns the last empty row from the sheet.- Parameters:
sheetName-- Returns:
- Throws:
Exception
-
set
Set cell data.- Parameters:
sheetName-row-column-value-- Throws:
Exception
-
set
Set cell data.- Parameters:
sheetName-row-column-value-- Throws:
Exception
-
set
Set cell data.- Parameters:
sheetName-row-column-value-- Throws:
Exception
-
query
Set cell data.- Parameters:
sql-- Returns:
- Throws:
SQLException
-