Search in sources :

Example 66 with HSSFRow

use of org.apache.poi.hssf.usermodel.HSSFRow in project adempiere by adempiere.

the class AbstractExcelExporter method createTableHeader.

private void createTableHeader(HSSFSheet sheet) {
    short colnumMax = 0;
    HSSFRow row = sheet.createRow(0);
    //	for all columns
    short colnum = 0;
    for (int col = 0; col < getColumnCount(); col++) {
        if (colnum > colnumMax)
            colnumMax = colnum;
        //
        if (isColumnPrinted(col)) {
            HSSFCell cell = row.createCell(colnum);
            //	header row
            HSSFCellStyle style = getHeaderStyle(col);
            cell.setCellStyle(style);
            String str = fixString(getHeaderName(col));
            cell.setCellValue(new HSSFRichTextString(str));
            colnum++;
        }
    //	printed
    }
//	for all columns
//		m_workbook.setRepeatingRowsAndColumns(m_sheetCount, 0, 0, 0, 0);
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Example 67 with HSSFRow

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

the class Outlines method test1.

public String test1() {
    sheet1.groupColumn(4, 7);
    for (int row = 0; row < 200; row++) {
        HSSFRow r = sheet1.createRow(row);
        for (int column = 0; column < 200; column++) {
            HSSFCell c = r.createCell(column);
            c.setCellValue(column);
        }
    }
    return "Two expanded groups.";
}
Also used : HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow)

Example 68 with HSSFRow

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

the class ReadWriteWorkbook method main.

public static void main(String[] args) throws IOException {
    FileInputStream fileIn = null;
    FileOutputStream fileOut = null;
    try {
        fileIn = new FileInputStream("workbook.xls");
        POIFSFileSystem fs = new POIFSFileSystem(fileIn);
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFRow row = sheet.getRow(2);
        if (row == null)
            row = sheet.createRow(2);
        HSSFCell cell = row.getCell(3);
        if (cell == null)
            cell = row.createCell(3);
        cell.setCellType(CellType.STRING);
        cell.setCellValue("a test");
        // Write the output to a file
        fileOut = new FileOutputStream("workbookout.xls");
        wb.write(fileOut);
    } finally {
        if (fileOut != null)
            fileOut.close();
        if (fileIn != null)
            fileIn.close();
    }
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) 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) FileInputStream(java.io.FileInputStream) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 69 with HSSFRow

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

the class CreateCells method main.

public static void main(String[] args) throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("new sheet");
    // Create a row and put some cells in it. Rows are 0 based.
    HSSFRow row = sheet.createRow(0);
    // Create a cell and put a value in it.
    HSSFCell cell = row.createCell(0);
    cell.setCellValue(1);
    // Or do it on one line.
    row.createCell(1).setCellValue(1.2);
    row.createCell(2).setCellValue("This is a string");
    row.createCell(3).setCellValue(true);
    // 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) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 70 with HSSFRow

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

the class CreateDateCells method main.

public static void main(String[] args) throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("new sheet");
    // Create a row and put some cells in it. Rows are 0 based.
    HSSFRow row = sheet.createRow(0);
    // Create a cell and put a date value in it.  The first cell is not styled as a date.
    HSSFCell cell = row.createCell(0);
    cell.setCellValue(new Date());
    // we style the second cell as a date (and time).  It is important to create a new cell style from the workbook
    // otherwise you can end up modifying the built in style and effecting not only this cell but other cells.
    HSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
    cell = row.createCell(1);
    cell.setCellValue(new Date());
    cell.setCellStyle(cellStyle);
    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream("workbook.xls");
    wb.write(fileOut);
    fileOut.close();
    wb.close();
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) 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) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Date(java.util.Date)

Aggregations

HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)124 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)98 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)82 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)71 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)29 FileOutputStream (java.io.FileOutputStream)24 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)24 Test (org.junit.Test)18 IOException (java.io.IOException)16 HSSFFormulaEvaluator (org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator)15 HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)14 File (java.io.File)13 ArrayList (java.util.ArrayList)12 CellValue (org.apache.poi.ss.usermodel.CellValue)10 OutputStream (java.io.OutputStream)8 HashMap (java.util.HashMap)8 Map (java.util.Map)7 AssertionFailedError (junit.framework.AssertionFailedError)7 FileInputStream (java.io.FileInputStream)6 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)6