poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 23958] New: - Cannot get a the template feature to work when writing to an excel file.
Date Mon, 20 Oct 2003 22:05:35 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23958>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23958

Cannot get a the template feature to work when writing to an excel file.

           Summary: Cannot get a the template feature to work when writing
                    to an excel file.
           Product: POI
           Version: 2.0-pre3
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Major
          Priority: Other
         Component: POI Overall
        AssignedTo: poi-dev@jakarta.apache.org
        ReportedBy: mjmoore@strong.com


I am trying to create a footer with formulas to set the printable area and 
footer text when printing the an excel report.  When I implemented using a 
template to satisfy this requirement, the excel sheet started being created as 
blank.  There is data being put into the object, but when I got to write that 
data to the excel sheet, it comes out as blank.  Here is some sample code.  
Please let me know if I am doing something wrong here.

public void generate(LevelOfProcessing aLevel, String excelFileTemplate, String 
excelFileName)
            throws ReportGenerationException {

        //clear out instance variables so this method
        //can be called multiple times for the same payroll file
        initialize();

        this.level = aLevel;
        //this.excelFileTemplate = excelFileTemplate;

        createSpreadsheet();
        createHeader();
        
        writeExcelFile(excelFileName);

    }

 private void createSpreadsheet() {
        if (this.excelFileTemplate != null) {
            if (logging.isInfoEnabled()) {
                logging.info("Reading from excel template file " + 
this.excelFileTemplate);
            }
             
         try {

	     InputStream templateStream = 
ClasspathResourceLocator.getResourceStream(this.excelFileTemplate);
             this.workbook = new ExcelWorkbook(templateStream);
             this.workbook = new ExcelWorkbook();
             this.sheet = this.workbook.getSheet(REPORT_NAME);
             templateStream.close();
	    } catch (FileNotFoundException fnfe) {
                if (logging.isDebugEnabled()) {
                    logging.debug("Unable to read from file " + 
this.excelFileTemplate +
                            ".  Creating a new workbook.");
                }
                this.workbook = new ExcelWorkbook();
                this.sheet = this.workbook.createSheet(REPORT_NAME);

            } catch (IOException ioe) {
                if (logging.isDebugEnabled()) {
                    logging.debug("Unable to read from file " + 
this.excelFileTemplate +
                            ". Creating a new workbook.");
                }
                this.workbook = new ExcelWorkbook();
                this.sheet = this.workbook.createSheet(REPORT_NAME);

            } catch (ResourceNotFoundException rnfe) {
                if (logging.isDebugEnabled()) {
                    logging.debug("Unable to find file " + 
this.excelFileTemplate +
                            ". Creating a new workbook.");
                }
                this.workbook = new ExcelWorkbook();
                this.sheet = this.workbook.createSheet(REPORT_NAME);

            }
        } else {
            if (logging.isInfoEnabled()) {
                logging.info("Excel template file not specified.  Creating a 
new workbook.");
            }

            this.workbook = new ExcelWorkbook();
            this.sheet = this.workbook.createSheet(REPORT_NAME);

        }

        this.sheet.setColumnWidth((short) 0, (short) (15 * 256));
        this.sheet.setColumnWidth((short) 1, (short) (12 * 256));
        this.sheet.setColumnWidth((short) 2, (short) (10 * 256));
        this.sheet.setColumnWidth((short) 3, (short) (50 * 256));
        this.sheet.setColumnWidth((short) 4, (short) (13 * 256));
        this.sheet.setColumnWidth((short) 5, (short) (35 * 256));
        this.sheet.setColumnWidth((short) 6, (short) (35 * 256));
        this.sheet.setFitToPage(true);
    }
 private void createHeader() {

        row = this.sheet.createRow(HEADER_ROW);
        ExcelCell cell = row.getOrCreateCell(HEADER_COLUMN);
        cell.setCellTypeString();
        cell.setCellValue(STRONG);
        cell.setCellStyle(getTitleStyle());

        row = this.sheet.createRow((short) (HEADER_ROW + 1));
        cell = row.getOrCreateCell(HEADER_COLUMN);
        cell.setCellTypeString();
        cell.setCellValue(REPORT_NAME);
        cell.setCellStyle(getTitleStyle());

    }

private void writeExcelFile(String excelFileName)
            throws ReportGenerationException {

        Long payrollKey = payrollData.getPayrollFile().getId().getLongValue
("payroll_file_key");
        Long levelKey = this.level.getId().getLongValue("level_key");

        try {
            if (logging.isInfoEnabled()) {
                logging.info("Writing edit report for payroll file key " + 
payrollKey.toString() +
                        " and level key " + levelKey.toString() +
                        " to file " + excelFileName);
            }
            FileOutputStream out = new FileOutputStream(excelFileName);

            this.workbook.write(out);
            out.close();

        } catch (FileNotFoundException fnfe) {
            if (logging.isDebugEnabled()) {
                logging.debug("Unable to write to file " + excelFileName +
                        " for payroll file key " + payrollKey.toString() +
                        " and level key " + levelKey.toString(),
                        fnfe);
            }
            throw new ReportGenerationException(fnfe, "Unable to write edit 
report to " + excelFileName);

        } catch (IOException ioe) {
            if (logging.isDebugEnabled()) {
                logging.debug("Unable to write to file " + excelFileName +
                        " for payroll file key " + payrollKey.toString() +
                        " and level key " + levelKey.toString(),
                        ioe);

            }
            throw new ReportGenerationException(ioe, "Unable to write edit 
report to " + excelFileName);
        }
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org


Mime
View raw message