Search in sources :

Example 36 with CreationHelper

use of org.apache.poi.ss.usermodel.CreationHelper in project Aspose.Cells-for-Java by aspose-cells.

the class ApacheInsertCellsData method main.

public static void main(String[] args) throws Exception {
    // The path to the documents directory.
    String dataDir = Utils.getDataDir(ApacheInsertCellsData.class);
    Workbook wb = new HSSFWorkbook();
    CreationHelper createHelper = wb.getCreationHelper();
    Sheet sheet = wb.createSheet("new sheet");
    // Create a row and put some cells in it. Rows are 0 based.
    Row row = sheet.createRow((short) 0);
    // Create a cell and put a value in it.
    Cell cell = row.createCell(0);
    cell.setCellValue(1);
    // Or do it on one line.
    row.createCell(1).setCellValue(1.2);
    row.createCell(2).setCellValue(createHelper.createRichTextString("This is a string"));
    row.createCell(3).setCellValue(true);
    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream(dataDir + "DataInCells_Apache_Out.xls");
    wb.write(fileOut);
    fileOut.close();
    // Print message
    System.out.println("Data Added Successfully");
}
Also used : CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) FileOutputStream(java.io.FileOutputStream) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 37 with CreationHelper

use of org.apache.poi.ss.usermodel.CreationHelper in project ART-TIME by Artezio.

the class XlsxEmitter method setComment.

private void setComment(Cell cell, String commentText) {
    CreationHelper factory = getHandlerState().getWb().getCreationHelper();
    Sheet sheet = getHandlerState().currentSheet;
    Drawing drawing = sheet.createDrawingPatriarch();
    ClientAnchor anchor = factory.createClientAnchor();
    anchor.setCol1(cell.getColumnIndex() + 2);
    anchor.setCol2(cell.getColumnIndex() + 5);
    anchor.setRow1(cell.getRowIndex() - 1);
    anchor.setRow2(cell.getRowIndex() + 3);
    Comment comment = drawing.createCellComment(anchor);
    RichTextString str = factory.createRichTextString(commentText);
    comment.setString(str);
    cell.setCellComment(comment);
}
Also used : Drawing(org.apache.poi.ss.usermodel.Drawing) Comment(org.apache.poi.ss.usermodel.Comment) ClientAnchor(org.apache.poi.ss.usermodel.ClientAnchor) CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) RichTextString(org.apache.poi.ss.usermodel.RichTextString) Sheet(org.apache.poi.ss.usermodel.Sheet)

Aggregations

CreationHelper (org.apache.poi.ss.usermodel.CreationHelper)37 Sheet (org.apache.poi.ss.usermodel.Sheet)21 Cell (org.apache.poi.ss.usermodel.Cell)19 Workbook (org.apache.poi.ss.usermodel.Workbook)19 Row (org.apache.poi.ss.usermodel.Row)17 CellStyle (org.apache.poi.ss.usermodel.CellStyle)15 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)15 Font (org.apache.poi.ss.usermodel.Font)14 ClientAnchor (org.apache.poi.ss.usermodel.ClientAnchor)12 FileOutputStream (java.io.FileOutputStream)10 RichTextString (org.apache.poi.ss.usermodel.RichTextString)10 Test (org.junit.Test)9 Comment (org.apache.poi.ss.usermodel.Comment)8 Hyperlink (org.apache.poi.ss.usermodel.Hyperlink)8 IOException (java.io.IOException)7 Drawing (org.apache.poi.ss.usermodel.Drawing)5 OutputStream (java.io.OutputStream)4 ArrayList (java.util.ArrayList)4 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)4 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)3