https://bz.apache.org/bugzilla/show_bug.cgi?id=65800

--- Comment #7 from Prasenjitd <[email protected]> ---
Please find the sample code.

package com.cara.download.excel.main;



import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;



import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;



public class CreateWorksheet2 {



private FileOutputStream fileOut;



public void createWorkSheet(XSSFWorkbook wb, String content, String tabName) {
StringBuilder sbFileName = new StringBuilder();
sbFileName.append("test_excel.xlsx");
String fileMacTest = sbFileName.toString();
try {
this.fileOut = new FileOutputStream(fileMacTest);
} catch (FileNotFoundException ex) {
}



Sheet sheet = wb.createSheet(tabName); // Create new sheet w/ Tab name



sheet.setZoom(100); // Set sheet zoom: 100%



// begin insertion of values into cells
Row dataRow = sheet.createRow(0);
Cell A = dataRow.createCell(0);
XSSFRichTextString richText = new XSSFRichTextString();
for (int i = 0; i < content.length(); i++) {
Font currentFont = wb.createFont();
currentFont.setItalic(true); // italic creates space
currentFont.setUnderline(Font.U_SINGLE);
if (currentFont != null)
richText.append(Character.toString(content.charAt(i)), (XSSFFont) currentFont);



}
A.setCellValue(richText);
sheet.autoSizeColumn(0);



try {
// Write the output to a file
wb.write(fileOut);
fileOut.close();



} catch (IOException ex) {
}



}



public static void main(String[] args) {
String content = "GREH"; // content to be added to excel
CreateWorksheet2 createWorksheet = new CreateWorksheet2();
XSSFWorkbook wb = new XSSFWorkbook();
String tabName = "Sheet1";
createWorksheet.createWorkSheet(wb, content, tabName);
}



}

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to