How to define a cell style
import java.io.File;
import java.io.FileWriter;
import com.ytapi.xls4j.*;
...
Workbook workbook = new Workbook();
Style myStyle = workbook.createStyle("underlined");
myStyle.getFont().setUnderline(Font.UNDERLINE_SINGLE);
myStyle.createBorder(Border.POSITION_RIGHT).setLineStyle(Border.LINESTYLE_DASH);
|
We just defined a style named "underlined", with a single underlined font, and with a border at right which has the dash line appearance.
How to create a cell
Worksheet myWorksheet = workbook.createWorksheet("sample");
Cell aCell = myWorksheet.createCell(1, 1);
aCell.setDataValue("myFirstCell");
aCell.setStyleId("underlined");
|
We just created a worksheet named "sample" and added in it a cell in position (1, 1) with "myFirstCell" content, then we applied our "underlined" style on it.
How to generate our Excel document
String result = workbook.getXml();
File destination = new File("D:/work/test.xml");
FileWriter destinationFile = new FileWriter(destination);
destinationFile.write(result);
destinationFile.close();
|
We stored the xml into the result String, then write it in the "D:/work/test.xml" file.
|