Search in sources :

Example 11 with XSSFRichTextString

use of org.apache.poi.xssf.usermodel.XSSFRichTextString in project Gargoyle by callakrsos.

the class ExcelUtil method addComment.

/**
	 * 특정셀에 코멘트를 추가한다.
	 *
	 * @param sheet
	 * @param cell
	 * @param commentText
	 * @return
	 */
public static void addComment(Sheet sheet, Cell cell, String commentText) {
    XSSFDrawing patr = (XSSFDrawing) sheet.createDrawingPatriarch();
    Comment comment = patr.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 4, 2, (short) 6, 5));
    comment.setString(new XSSFRichTextString(commentText));
    cell.setCellComment(comment);
}
Also used : Comment(org.apache.poi.ss.usermodel.Comment) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) XSSFClientAnchor(org.apache.poi.xssf.usermodel.XSSFClientAnchor) XSSFDrawing(org.apache.poi.xssf.usermodel.XSSFDrawing)

Example 12 with XSSFRichTextString

use of org.apache.poi.xssf.usermodel.XSSFRichTextString in project cubrid-manager by CUBRID.

the class XlsxReaderHandler method endElement.

/**
	 * response the event end an element
	 *
	 * @param uri the uri of namespace
	 * @param localName the local name
	 * @param name the element name
	 * @throws SAXException the SAXException
	 */
public void endElement(String uri, String localName, String name) throws SAXException {
    if ("v".equals(name) || "t".equals(name)) {
        if (nextIsString) {
            try {
                int idx = Integer.parseInt(lastContents);
                lastContents = new XSSFRichTextString(sharedStringTable.getEntryAt(idx)).toString();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        String value = lastContents;
        if ("".equals(value)) {
            return;
        }
        value = "".equals(value) ? " " : value;
        int cols = currentCol - preCol;
        if (cols > 1) {
            for (int i = 0; i < cols - 1; i++) {
                rowlist.add(preCol, "");
            }
        }
        preCol = currentCol;
        rowlist.add(currentCol - 1, value);
    } else {
        if ("row".equals(name)) {
            if (rowlist.isEmpty()) {
                return;
            }
            int tmpCols = rowlist.size();
            if (currentRow > this.titleRow && tmpCols < this.colsize) {
                for (int i = 0; i < this.colsize - tmpCols; i++) {
                    rowlist.add(rowlist.size(), "");
                }
            }
            try {
                operateRows(sheetIndex, rowlist);
            } catch (DataFormatException e) {
                throw new RuntimeException(e);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
            if (currentRow == this.titleRow) {
                this.colsize = rowlist.size();
            }
            rowlist.clear();
            currentRow++;
            currentCol = 0;
            preCol = 0;
        }
    }
}
Also used : XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) DataFormatException(com.cubrid.common.ui.cubrid.table.dialog.DataFormatException) SQLException(java.sql.SQLException) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) SQLException(java.sql.SQLException) SAXException(org.xml.sax.SAXException) DataFormatException(com.cubrid.common.ui.cubrid.table.dialog.DataFormatException)

Example 13 with XSSFRichTextString

use of org.apache.poi.xssf.usermodel.XSSFRichTextString in project cubrid-manager by CUBRID.

the class XlsxRowNumberHandler method endElement.

/**
	 * Response to reading the end of an element
	 *
	 * @param uri the uri of namespace
	 * @param localName the local name
	 * @param name the element name
	 * @throws SAXException the SAXException
	 */
public void endElement(String uri, String localName, String name) throws SAXException {
    if (numberAllRow == 1 && ("v".equals(name) || "t".equals(name))) {
        if (nextIsString) {
            try {
                int idx = Integer.parseInt(contents);
                contents = new XSSFRichTextString(sharedStringTable.getEntryAt(idx)).toString();
            } catch (Exception e) {
                LOGGER.error(e.getMessage());
            }
        }
        String value = contents.trim();
        if ("".equals(value)) {
            return;
        }
        value = "".equals(value) ? " " : value;
        firstRowLst.add(cols, value);
        cols++;
    }
}
Also used : XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Example 14 with XSSFRichTextString

use of org.apache.poi.xssf.usermodel.XSSFRichTextString in project poi by apache.

the class FillsAndColors method main.

public static void main(String[] args) throws IOException {
    //or new HSSFWorkbook();
    Workbook wb = new XSSFWorkbook();
    Sheet sheet = wb.createSheet("new sheet");
    // Create a row and put some cells in it. Rows are 0 based.
    Row row = sheet.createRow(1);
    // Aqua background
    CellStyle style = wb.createCellStyle();
    style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
    style.setFillPattern(FillPatternType.BIG_SPOTS);
    Cell cell = row.createCell(1);
    cell.setCellValue(new XSSFRichTextString("X"));
    cell.setCellStyle(style);
    // Orange "foreground", foreground being the fill foreground not the font color.
    style = wb.createCellStyle();
    style.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
    style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    cell = row.createCell(2);
    cell.setCellValue(new XSSFRichTextString("X"));
    cell.setCellStyle(style);
    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream("fill_colors.xlsx");
    wb.write(fileOut);
    fileOut.close();
    wb.close();
}
Also used : XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) FileOutputStream(java.io.FileOutputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Row(org.apache.poi.ss.usermodel.Row) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook)

Example 15 with XSSFRichTextString

use of org.apache.poi.xssf.usermodel.XSSFRichTextString in project poi by apache.

the class TestXSSFChartTitle method testExistingChartWithTitle.

@Test
public void testExistingChartWithTitle() throws IOException {
    Workbook wb = XSSFTestDataSamples.openSampleWorkbook("chartTitle_withTitle.xlsx");
    XSSFChart chart = getChartFromWorkbook(wb, "Sheet1");
    assertNotNull(chart);
    XSSFRichTextString originalTitle = chart.getTitleText();
    assertNotNull(originalTitle);
    final String myTitle = "My chart title";
    assertFalse(myTitle.equals(originalTitle.toString()));
    chart.setTitleText(myTitle);
    XSSFRichTextString queryTitle = chart.getTitleText();
    assertNotNull(queryTitle);
    assertEquals(myTitle, queryTitle.toString());
    wb.close();
}
Also used : XSSFChart(org.apache.poi.xssf.usermodel.XSSFChart) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) Test(org.junit.Test)

Aggregations

XSSFRichTextString (org.apache.poi.xssf.usermodel.XSSFRichTextString)17 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)7 Workbook (org.apache.poi.ss.usermodel.Workbook)6 Test (org.junit.Test)5 XSSFChart (org.apache.poi.xssf.usermodel.XSSFChart)4 Cell (org.apache.poi.ss.usermodel.Cell)3 Row (org.apache.poi.ss.usermodel.Row)3 FileOutputStream (java.io.FileOutputStream)2 CellStyle (org.apache.poi.ss.usermodel.CellStyle)2 CellType (org.apache.poi.ss.usermodel.CellType)2 Comment (org.apache.poi.ss.usermodel.Comment)2 Sheet (org.apache.poi.ss.usermodel.Sheet)2 XSSFClientAnchor (org.apache.poi.xssf.usermodel.XSSFClientAnchor)2 SAXException (org.xml.sax.SAXException)2 DataFormatException (com.cubrid.common.ui.cubrid.table.dialog.DataFormatException)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)1 FormulaError (org.apache.poi.ss.usermodel.FormulaError)1 RichTextString (org.apache.poi.ss.usermodel.RichTextString)1