Search in sources :

Example 1 with org.openxmlformats.schemas.spreadsheetml.x2006.main

use of org.openxmlformats.schemas.spreadsheetml.x2006.main in project poi by apache.

the class HybridStreaming method main.

public static void main(String[] args) throws IOException, SAXException {
    InputStream sourceBytes = new FileInputStream("workbook.xlsx");
    XSSFWorkbook workbook = new XSSFWorkbook(sourceBytes) {

        /** Avoid DOM parse of large sheet */
        @Override
        public void parseSheet(java.util.Map<String, XSSFSheet> shIdMap, CTSheet ctSheet) {
            if (!SHEET_TO_STREAM.equals(ctSheet.getName())) {
                super.parseSheet(shIdMap, ctSheet);
            }
        }
    };
    // Having avoided a DOM-based parse of the sheet, we can stream it instead.
    ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(workbook.getPackage());
    new XSSFSheetXMLHandler(workbook.getStylesSource(), strings, createSheetContentsHandler(), false);
    workbook.close();
    sourceBytes.close();
}
Also used : ReadOnlySharedStringsTable(org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable) CTSheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) FileInputStream(java.io.FileInputStream) XSSFSheetXMLHandler(org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler)

Example 2 with org.openxmlformats.schemas.spreadsheetml.x2006.main

use of org.openxmlformats.schemas.spreadsheetml.x2006.main in project poi by apache.

the class CreateTable method main.

public static void main(String[] args) throws IOException {
    Workbook wb = new XSSFWorkbook();
    XSSFSheet sheet = (XSSFSheet) wb.createSheet();
    //Create 
    XSSFTable table = sheet.createTable();
    table.setDisplayName("Test");
    CTTable cttable = table.getCTTable();
    //Style configurations
    CTTableStyleInfo style = cttable.addNewTableStyleInfo();
    style.setName("TableStyleMedium2");
    style.setShowColumnStripes(false);
    style.setShowRowStripes(true);
    //Set which area the table should be placed in
    AreaReference reference = new AreaReference(new CellReference(0, 0), new CellReference(2, 2));
    cttable.setRef(reference.formatAsString());
    cttable.setId(1);
    cttable.setName("Test");
    cttable.setTotalsRowCount(1);
    CTTableColumns columns = cttable.addNewTableColumns();
    columns.setCount(3);
    CTTableColumn column;
    XSSFRow row;
    XSSFCell cell;
    for (int i = 0; i < 3; i++) {
        //Create column
        column = columns.addNewTableColumn();
        column.setName("Column");
        column.setId(i + 1);
        //Create row
        row = sheet.createRow(i);
        for (int j = 0; j < 3; j++) {
            //Create cell
            cell = row.createCell(j);
            if (i == 0) {
                cell.setCellValue("Column" + j);
            } else {
                cell.setCellValue("0");
            }
        }
    }
    FileOutputStream fileOut = new FileOutputStream("ooxml-table.xlsx");
    wb.write(fileOut);
    fileOut.close();
    wb.close();
}
Also used : AreaReference(org.apache.poi.ss.util.AreaReference) CTTableColumns(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumns) CellReference(org.apache.poi.ss.util.CellReference) XSSFTable(org.apache.poi.xssf.usermodel.XSSFTable) CTTableColumn(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableColumn) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) CTTableStyleInfo(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTableStyleInfo) FileOutputStream(java.io.FileOutputStream) CTTable(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTTable) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell)

Example 3 with org.openxmlformats.schemas.spreadsheetml.x2006.main

use of org.openxmlformats.schemas.spreadsheetml.x2006.main in project poi by apache.

the class TestXSSFSheet method setForceFormulaRecalculation.

/**
     * Test to trigger OOXML-LITE generating to include org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetCalcPr
     */
@Test
public void setForceFormulaRecalculation() throws IOException {
    XSSFWorkbook wb1 = new XSSFWorkbook();
    XSSFSheet sheet = wb1.createSheet("Sheet 1");
    assertFalse(sheet.getForceFormulaRecalculation());
    // Set
    sheet.setForceFormulaRecalculation(true);
    assertTrue(sheet.getForceFormulaRecalculation());
    // calcMode="manual" is unset when forceFormulaRecalculation=true
    CTCalcPr calcPr = wb1.getCTWorkbook().addNewCalcPr();
    calcPr.setCalcMode(STCalcMode.MANUAL);
    sheet.setForceFormulaRecalculation(true);
    assertEquals(STCalcMode.AUTO, calcPr.getCalcMode());
    // Check
    sheet.setForceFormulaRecalculation(false);
    assertFalse(sheet.getForceFormulaRecalculation());
    // Save, re-load, and re-check
    XSSFWorkbook wb2 = XSSFTestDataSamples.writeOutAndReadBack(wb1);
    wb1.close();
    sheet = wb2.getSheet("Sheet 1");
    assertFalse(sheet.getForceFormulaRecalculation());
    wb2.close();
}
Also used : CTCalcPr(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCalcPr) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) Test(org.junit.Test)

Example 4 with org.openxmlformats.schemas.spreadsheetml.x2006.main

use of org.openxmlformats.schemas.spreadsheetml.x2006.main in project SoftUni by kostovhg.

the class p14_ExportToExcel method main.

public static void main(String[] args) throws IOException {
    ArrayList<Object[]> allLines = new ArrayList<>();
    allLines.add(new Object[] { "FN", "First name", "Last Name", "Email", "Age", "Group", "Grade1", "Grade2", "Grade3", "Grade4", "Phones" });
    new BufferedReader(new FileReader("StudentsData.txt")).lines().map(x -> x.split("\\t")).filter(x -> !x[0].equals("FN")).forEach(allLines::add);
    // Create workbook and worksheet object
    int rowStart = 2;
    int columnStart = 0;
    int totalRows = allLines.size();
    int totalCols = allLines.get(0).length;
    int rowEnd = totalRows + rowStart - 1;
    int colEnd = totalCols + columnStart - 1;
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet sheet = workbook.createSheet("SoftUniOOPCourseResults");
    CellStyle style1 = workbook.createCellStyle();
    style1.setAlignment(HorizontalAlignment.RIGHT);
    XSSFDataFormat intFormat = workbook.createDataFormat();
    style1.setDataFormat(intFormat.getFormat("0"));
    CellStyle style2 = workbook.createCellStyle();
    XSSFDataFormat strFormat = workbook.createDataFormat();
    style2.setDataFormat(strFormat.getFormat("General"));
    style2.setAlignment(HorizontalAlignment.LEFT);
    XSSFRow row;
    XSSFCell cell;
    // Create an object of type XSSFTable
    XSSFTable myTable = sheet.createTable();
    // Get CTTable object
    CTTable cttable = myTable.getCTTable();
    cttable.setTotalsRowShown(false);
    // Define the required style1 for the table
    CTTableStyleInfo table_style = cttable.addNewTableStyleInfo();
    table_style.setName("TableStyleLight14");
    // Set table style option
    table_style.setShowColumnStripes(false);
    table_style.setShowRowStripes(true);
    // define the data range including headers
    AreaReference my_data_range = new AreaReference(new CellReference(rowStart, columnStart), new CellReference(rowEnd, colEnd));
    // Set range to the table
    cttable.setRef(my_data_range.formatAsString());
    cttable.setDisplayName("Students");
    cttable.setName("Students");
    cttable.setId(1L);
    CTTableColumns columns = cttable.addNewTableColumns();
    CTAutoFilter autoFilter = cttable.addNewAutoFilter();
    columns.setCount(totalCols);
    // Define Header Information for the table
    for (int i = columnStart; i <= colEnd; i++) {
        CTTableColumn column = columns.addNewTableColumn();
        column.setName(allLines.get(0)[i].toString());
        column.setId(i + 1);
    }
    sheet.setAutoFilter(new CellRangeAddress(rowStart, rowStart, columnStart, colEnd));
    // Add remaining Table data
    row = sheet.createRow((short) 0);
    cell = row.createCell((short) 0);
    sheet.addMergedRegion(new CellRangeAddress(0, rowStart - 1, columnStart, colEnd));
    cell.setCellValue("SoftUni OOP Course Results");
    CellStyle bolded = workbook.createCellStyle();
    bolded.setAlignment(HorizontalAlignment.CENTER);
    XSSFFont myFont = workbook.createFont();
    myFont.setBold(true);
    myFont.setFontHeightInPoints((short) 30);
    bolded.setFont(myFont);
    cell.setCellStyle(bolded);
    int rowNum = rowStart;
    for (Object[] datatype : allLines) {
        XSSFRow inRow = sheet.createRow(rowNum++);
        int colNum = columnStart;
        for (Object field : datatype) {
            XSSFCell inCell = inRow.createCell(colNum++);
            if (isInt(field)) {
                inCell.setCellStyle(style1);
                inCell.setCellType(CellType.NUMERIC);
                inCell.setCellValue((Double) field);
            } else {
                inCell.setCellStyle(style2);
                inCell.setCellType(CellType.STRING);
                inCell.setCellValue((String) field);
            }
        }
    }
    for (int i = 1; i <= 11; i++) {
        sheet.autoSizeColumn(i);
    }
    try {
        FileOutputStream outputStream = new FileOutputStream(FILE_NAME);
        workbook.write(outputStream);
        workbook.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("Done");
}
Also used : org.apache.poi.ss.usermodel(org.apache.poi.ss.usermodel) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) org.apache.poi.xssf.usermodel(org.apache.poi.xssf.usermodel) AreaReference(org.apache.poi.ss.util.AreaReference) java.io(java.io) org.openxmlformats.schemas.spreadsheetml.x2006.main(org.openxmlformats.schemas.spreadsheetml.x2006.main) CellReference(org.apache.poi.ss.util.CellReference) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) CellReference(org.apache.poi.ss.util.CellReference) AreaReference(org.apache.poi.ss.util.AreaReference) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress)

Example 5 with org.openxmlformats.schemas.spreadsheetml.x2006.main

use of org.openxmlformats.schemas.spreadsheetml.x2006.main in project universa by UniversaBlockchain.

the class CLIMainTest method createMain.

static Main createMain(String name, boolean nolog) throws InterruptedException {
    String path = new File("src/test_node_config_v2/" + name).getAbsolutePath();
    System.out.println(path);
    String[] args = new String[] { "--test", "--config", path, nolog ? "--nolog" : "" };
    Main main = new Main(args);
    main.config.setTransactionUnitsIssuerKeyData(Bytes.fromHex("1E 08 1C 01 00 01 C4 00 01 B9 C7 CB 1B BA 3C 30 80 D0 8B 29 54 95 61 41 39 9E C6 BB 15 56 78 B8 72 DC 97 58 9F 83 8E A0 B7 98 9E BB A9 1D 45 A1 6F 27 2F 61 E0 26 78 D4 9D A9 C2 2F 29 CB B6 F7 9F 97 60 F3 03 ED 5C 58 27 27 63 3B D3 32 B5 82 6A FB 54 EA 26 14 E9 17 B6 4C 5D 60 F7 49 FB E3 2F 26 52 16 04 A6 5E 6E 78 D1 78 85 4D CD 7B 71 EB 2B FE 31 39 E9 E0 24 4F 58 3A 1D AE 1B DA 41 CA 8C 42 2B 19 35 4B 11 2E 45 02 AD AA A2 55 45 33 39 A9 FD D1 F3 1F FA FE 54 4C 2E EE F1 75 C9 B4 1A 27 5C E9 C0 42 4D 08 AD 3E A2 88 99 A3 A2 9F 70 9E 93 A3 DF 1C 75 E0 19 AB 1F E0 82 4D FF 24 DA 5D B4 22 A0 3C A7 79 61 41 FD B7 02 5C F9 74 6F 2C FE 9A DD 36 44 98 A2 37 67 15 28 E9 81 AC 40 CE EF 05 AA 9E 36 8F 56 DA 97 10 E4 10 6A 32 46 16 D0 3B 6F EF 80 41 F3 CC DA 14 74 D1 BF 63 AC 28 E0 F1 04 69 63 F7"));
    main.config.getKeysWhiteList().add(main.config.getTransactionUnitsIssuerKey());
    main.waitReady();
    return main;
}
Also used : File(java.io.File) Main(com.icodici.universa.node2.Main)

Aggregations

Main (com.icodici.universa.node2.Main)2 AreaReference (org.apache.poi.ss.util.AreaReference)2 CellReference (org.apache.poi.ss.util.CellReference)2 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)2 java.io (java.io)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 org.apache.poi.ss.usermodel (org.apache.poi.ss.usermodel)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)1 ReadOnlySharedStringsTable (org.apache.poi.xssf.eventusermodel.ReadOnlySharedStringsTable)1 XSSFSheetXMLHandler (org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler)1 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)1 org.apache.poi.xssf.usermodel (org.apache.poi.xssf.usermodel)1 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)1 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)1 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)1