Search in sources :

Example 11 with HSSFWorkbook

use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.

the class SViewer method jbInit.

/**Component initialization*/
private void jbInit() throws Exception {
    InputStream i = null;
    boolean isurl = false;
    if (filename == null)
        filename = getParameter("filename");
    if (filename == null || filename.substring(0, 7).equals("http://")) {
        isurl = true;
        if (filename == null)
            filename = getParameter("url");
        i = getXLSFromURL(filename);
    }
    HSSFWorkbook wb = null;
    if (isurl) {
        wb = constructWorkbook(i);
    } else {
        wb = constructWorkbook(filename);
    }
    panel = new SViewerPanel(wb, false);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(panel, BorderLayout.CENTER);
}
Also used : HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 12 with HSSFWorkbook

use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.

the class MergedCells method main.

public static void main(String[] args) throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("new sheet");
    HSSFRow row = sheet.createRow(1);
    HSSFCell cell = row.createCell(1);
    cell.setCellValue("This is a test of merging");
    sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2));
    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream("workbook.xls");
    wb.write(fileOut);
    fileOut.close();
    wb.close();
}
Also used : HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) FileOutputStream(java.io.FileOutputStream) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 13 with HSSFWorkbook

use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.

the class SViewer method constructWorkbook.

private HSSFWorkbook constructWorkbook(String filename) throws FileNotFoundException, IOException {
    HSSFWorkbook wb = null;
    FileInputStream in = new FileInputStream(filename);
    wb = new HSSFWorkbook(in);
    in.close();
    return wb;
}
Also used : HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 14 with HSSFWorkbook

use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.

the class SViewer method constructWorkbook.

private HSSFWorkbook constructWorkbook(InputStream in) throws IOException {
    HSSFWorkbook wb = null;
    wb = new HSSFWorkbook(in);
    in.close();
    return wb;
}
Also used : HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 15 with HSSFWorkbook

use of org.apache.poi.hssf.usermodel.HSSFWorkbook in project poi by apache.

the class ReSave method main.

public static void main(String[] args) throws Exception {
    boolean initDrawing = false;
    boolean saveToMemory = false;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    for (String filename : args) {
        if (filename.equals("-dg")) {
            initDrawing = true;
        } else if (filename.equals("-bos")) {
            saveToMemory = true;
        } else {
            System.out.print("reading " + filename + "...");
            FileInputStream is = new FileInputStream(filename);
            HSSFWorkbook wb = new HSSFWorkbook(is);
            try {
                System.out.println("done");
                for (int i = 0; i < wb.getNumberOfSheets(); i++) {
                    HSSFSheet sheet = wb.getSheetAt(i);
                    if (initDrawing) {
                        /*HSSFPatriarch dg =*/
                        sheet.getDrawingPatriarch();
                    }
                }
                OutputStream os;
                if (saveToMemory) {
                    bos.reset();
                    os = bos;
                } else {
                    String outputFile = filename.replace(".xls", "-saved.xls");
                    System.out.print("saving to " + outputFile + "...");
                    os = new FileOutputStream(outputFile);
                }
                try {
                    wb.write(os);
                } finally {
                    os.close();
                }
                System.out.println("done");
            } finally {
                wb.close();
                is.close();
            }
        }
    }
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileInputStream(java.io.FileInputStream) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Aggregations

HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)532 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)189 Test (org.junit.Test)173 Workbook (org.apache.poi.ss.usermodel.Workbook)151 Sheet (org.apache.poi.ss.usermodel.Sheet)138 Row (org.apache.poi.ss.usermodel.Row)113 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)102 Cell (org.apache.poi.ss.usermodel.Cell)101 FileOutputStream (java.io.FileOutputStream)99 IOException (java.io.IOException)99 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)79 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)72 FileInputStream (java.io.FileInputStream)61 File (java.io.File)59 ArrayList (java.util.ArrayList)52 HSSFFormulaEvaluator (org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator)38 InputStream (java.io.InputStream)34 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)32 CellStyle (org.apache.poi.ss.usermodel.CellStyle)31 OutputStream (java.io.OutputStream)28