ASF Bugzilla – Attachment 24802 Details for
Bug 48493
Get NullPointerException in org.apache.xmlbeans.impl.store.Xobj.array_setter when creating Excel spreadsheet
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
The java class ExcelObj.java that is referenced in the bug text
ExcelObj.java (text/plain), 3.96 KB, created by
solomon.eugene
on 2010-01-06 09:33:20 UTC
(
hide
)
Description:
The java class ExcelObj.java that is referenced in the bug text
Filename:
MIME Type:
Creator:
solomon.eugene
Created:
2010-01-06 09:33:20 UTC
Size:
3.96 KB
patch
obsolete
>// BOOTLEG 01/04/2009 ****** >/* ExcelObj.java - > * SLED object to facilitate writing data to an Excel file. > * 09/05/2007 E.Solomon > * There are four public methods: > * void open(String inFileName) > * void startRow(int rowNum) > * void setCell(String cellValue) > * void close() throws FileNotFoundException, IOException > * > * Note that this needs to acces the jar file "poi...", which > * contains all the package org.apache.poi.hssf.usermodel > * 03/15/2008 E.Solomon > * Make the HSSFCellStyle object-level, to avoid getting > * warning messages when opening the spreadsheet in Excel. > * Make an alternate form of the open() method, where you can > * pass in the name of the worksheet. > * > * 03/20/2008 A. Moonjelly > * Modifications to write Header and footer > * Modifications to add font and font size (03/24/08) > * 08/29/2008 E.Solomon Make Excel display look more "normal": > * Increase font size, decrease row he > * 03/26/2009 E.Solomon In startRow(): make the argument to sheet.createRow() > * be "int" rather than "short" > * 01/05/2009 E.Solomon Upgrade to use Excel 2007 file format > */ >package gov.bls.dbes.sled.util; >import org.apache.poi.ss.usermodel.*; >import org.apache.poi.xssf.usermodel.*; >import org.apache.poi.hssf.usermodel.*; >import java.io.*; > >public class ExcelObj >{ > String fileName; > Workbook wb; > Sheet sheet; > Row row; > short cellNum; > CellStyle cellStyle; > CreationHelper createHelper; > > public void open(String inFileName, String headerString, String footerString) > throws IOException > { > open(inFileName, "sheet 0", headerString, footerString); > } > > public void open(String headerString, String footerString, > String inFileName, String sheetName) > throws IOException > { > // Create a New XL Document > wb = new XSSFWorkbook(); > // Make a worksheet in the XL document created > sheet = wb.createSheet(sheetName); // > createHelper = wb.getCreationHelper(); > > //AM create and set the font size > Font fnt = wb.createFont(); > fnt.setFontHeightInPoints((short) 10); // was 8 > > //AM - set the header and footer > Header currheader = sheet.getHeader(); > currheader.setCenter(headerString); > currheader.setRight("Page &P of &N"); > > Footer currfooter = sheet.getFooter(); > > // currfooter.setLeft(currfooter.fontSize((short)7)+footerString); > currfooter.setRight("&D - &T"); > > fileName = inFileName; > cellStyle = wb.createCellStyle(); > DataFormat format = wb.createDataFormat(); > cellStyle.setDataFormat(format.getFormat("@")); > cellStyle.setFont(fnt); > > } > > //public void startRow(int rowNum) > public void startRow(long rowNum) > { > // Create row at that index > row = sheet.createRow((int)rowNum); > row.setHeight((short) 0x125); // was 0x249 > cellNum = 0; > } > > public void setCell(String cellValue ) > { > // Create a cell at index zero ( Top Left) > Cell cell = row.createCell(cellNum++); > // Lets make the cell a string type > cell.setCellType(cell.CELL_TYPE_STRING); > cell.setCellStyle(cellStyle); > // cell.setCellValue(new HSSFRichTextString(cellValue)); > cell.setCellValue(createHelper.createRichTextString(cellValue)); > } > > public void close() > throws FileNotFoundException, IOException > { > // The Output file is where the xls will be created > FileOutputStream fOut = new FileOutputStream(fileName); > // Write the XL sheet > wb.write(fOut); > fOut.flush(); > // Done Deal.. > fOut.close(); > } > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 48493
: 24802