Forum
2011-12-06 18:22:12 UTC
I am using Apachi POI to create excel sheet using java. I am able to create
a workbook, create sheets and add rows and column cells. I have a
requirement where in I want to create a single cell which can hold multi
lines texts and each words in the sentence with different fonts.
For Example: I want to do the following as shown in the attached image.
<nabble_img src="multiline_excel_sample_data.jpg" border="0" alt="Multi
line in a single cell using poi"/>
Please help me with a sample code. I have written code to create a row with
2 columns. But I am unable to create a cell which has multi line texts with
varying font types as shown in the attached Book1.xls file (See row1 column
2 in the excel).
<nabble_a href="Book1.xls">Book1.xls</nabble_a>
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class TestExcel {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
try {
HSSFWorkbook workbook = new HSSFWorkbook();
FileOutputStream fileOut = new FileOutputStream("d:/Book2.xls");
HSSFSheet sheet1 = workbook.createSheet();
HSSFRow row1 = sheet1.createRow((short) 0);
HSSFCell cell1 = row1.createCell((short) 0);
cell1.setCellValue("This is Row 1 column 1.");
row1.createCell((short) 1).setCellValue("This is Row 1 column 2.");
workbook.write(fileOut);
fileOut.close();
} catch (Exception e) {
e.printStackTrace();
}
;
}
}
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Create-a-Cell-with-multi-line-text-using-Apachi-POI-tp5053020p5053020.html
Sent from the POI - User mailing list archive at Nabble.com.
a workbook, create sheets and add rows and column cells. I have a
requirement where in I want to create a single cell which can hold multi
lines texts and each words in the sentence with different fonts.
For Example: I want to do the following as shown in the attached image.
<nabble_img src="multiline_excel_sample_data.jpg" border="0" alt="Multi
line in a single cell using poi"/>
Please help me with a sample code. I have written code to create a row with
2 columns. But I am unable to create a cell which has multi line texts with
varying font types as shown in the attached Book1.xls file (See row1 column
2 in the excel).
<nabble_a href="Book1.xls">Book1.xls</nabble_a>
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class TestExcel {
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
try {
HSSFWorkbook workbook = new HSSFWorkbook();
FileOutputStream fileOut = new FileOutputStream("d:/Book2.xls");
HSSFSheet sheet1 = workbook.createSheet();
HSSFRow row1 = sheet1.createRow((short) 0);
HSSFCell cell1 = row1.createCell((short) 0);
cell1.setCellValue("This is Row 1 column 1.");
row1.createCell((short) 1).setCellValue("This is Row 1 column 2.");
workbook.write(fileOut);
fileOut.close();
} catch (Exception e) {
e.printStackTrace();
}
;
}
}
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Create-a-Cell-with-multi-line-text-using-Apachi-POI-tp5053020p5053020.html
Sent from the POI - User mailing list archive at Nabble.com.