Java Excel API
| Java Excel API | |
|---|---|
| Developers | Andy Khan, Eric H. Jung |
| Stable release | 2.6.12
/ 8 October 2012 |
| Written in | Java |
| Operating system | Cross-platform |
| Type | API to access Microsoft Excel format |
| License | GNU LGPL v2.1+[1] |
| Website | jexcelapi |
Java Excel API (a.k.a. JXL API) allows users to read, write, create, and modify sheets in an Excel (.xls) workbook at runtime. It does not support .xlsx format.[2]
Microsoft Excel support
Java Excel API supports Excel documents with versions Excel 95, 97, 2000, XP, and 2003. These documents hold the extension .xls.[2]
Usage
Java Excel API is widely used with Selenium.
Example
Sample code to write to an Excel file might look like as follows:
import java.io.File;
import jxl.Workbook;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.Label;
import jxl.write.WriteException;
public class DataSheet
{
private Workbook wbook;
private WritableWorkbook wwbCopy;
private WritableSheet shSheet;
public void readExcel()
{
try
{
wbook = Workbook.getWorkbook(new File("path/testSampleData.xls"));
wwbCopy = Workbook.createWorkbook(new File("path/testSampleDataCopy.xls"), wbook);
shSheet = wwbCopy.getSheet(0);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void setValueIntoCell(String strSheetName, int iColumnNumber, int iRowNumber, String strData) throws WriteException
{
WritableSheet wshTemp = wwbCopy.getSheet(strSheetName);
Label labTemp = new Label(iColumnNumber, iRowNumber, strData);
try
{
wshTemp.addCell(labTemp);
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void closeFile()
{
try
{
// Closing the writable work book
wwbCopy.write();
wwbCopy.close();
// Closing the original work book
wbook.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args) throws WriteException
{
DataSheet ds = new DataSheet();
ds.readExcel();
ds.setValueIntoCell("sheet1", 5, 1, "PASS");
ds.setValueIntoCell("sheet1", 5, 2, "FAIL");
ds.setValueIntoCell("sheet1", 5, 3, "PASS");
ds.closeFile();
}
}
See also
References
External links
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.