Can you distill that down to something that discreetly reproduces the problem?  
I tried copying and pasting that snippet into a class to run but it's not a 
complete example.

Thanks,

Jon






________________________________
From: snelligan <[email protected]>
To: [email protected]
Sent: Mon, June 20, 2011 8:04:22 AM
Subject: RE: Problem creating an .xlsx file using POI and XSSF

It is threaded through the application, but this is the main classs



package model;



import dbcp.TransactionManager;

import java.text.Format;

import java.util.*;

import java.sql.SQLException;

import org.apache.poi.ss.usermodel.*;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import org.apache.poi.xssf.usermodel.XSSFRow;

import org.apache.poi.xssf.usermodel.XSSFCell;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFCellStyle;

import org.jdom.Document;

import org.jdom.Element;

import org.jdom.input.DOMBuilder;

import java.io.*;

import view.HtmlMappable;

import javax.servlet.http.HttpSession;



..



    public synchronized String toExcel(final String pathPlusFile) throws
DataException {



        // create a new workBook

        final XSSFWorkbook book = new XSSFWorkbook();

        // create a new sheet w/i above workBook

        final XSSFSheet sheet = book.createSheet(this.recordName);

        // create a helper

        CreationHelper createHelper = book.getCreationHelper();

        // declare a row object reference

        XSSFRow row;

        // declare a cell object reference

        XSSFCell cell;

        // create Fonts

        boldFont = book.createFont();

        boldFont.setBoldweight(Font.BOLDWEIGHT_BOLD);

        // create cell Styles

        dateStyle = book.createCellStyle();


dateStyle.setDataFormat(createHelper.createDataFormat().getFormat("m/d/y
y"));

        timeStyle = book.createCellStyle();


timeStyle.setDataFormat(createHelper.createDataFormat().getFormat("m/d/y
y h:mm"));

        headerStyle = book.createCellStyle();

        headerStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);

        headerStyle.setFont(boldFont);



        Record firstRecord;

        // If no records, cannot export

        if (this.records.size() == 0) throw new DataException("Record
Set Contains No Rows");



        // Get reference to first record in set for creating column
heads and indexes

        firstRecord = (Record)this.records.get(0);



        // Array to contain column indexes and display order to export
to excel

        final int[] excelColumnIndexes = new
int[firstRecord.columns.length];

        int excelColumnCount = 0;



        // No columns specified - implicit - include all columns in xml
defined order

        if (this.excelColumnNames.size()== 0) {

            for (int i = 0; i < firstRecord.columns.length; i++) {

                excelColumnIndexes[excelColumnCount] = i;

                excelColumnCount++;

            }

        }

        // Build explicit ordered array of column indexes if specified
by setExcelColumnNames() method

        else {

            final Iterator i = this.excelColumnNames.iterator();

            while (i.hasNext()) {

                final String columnName = (String)i.next();

                try {

                    excelColumnIndexes[excelColumnCount] =
firstRecord.getColumnIndexByName(columnName);

                    excelColumnCount++;

                }

                catch (Exception e) {}

            }

        }



        // Create header row and column heading cells

        row = sheet.createRow((short)0);

        for (int i = 0; i < excelColumnCount; i++) {

            cell = row.createCell((short)i);

            final Column column =
firstRecord.columns[excelColumnIndexes[i]];

            cell.setCellValue(column.getColumnDefinition().getPrompt());

            cell.setCellStyle(headerStyle);

        }



        // Write specified filtered / sorted columns and records to
sheet

        int sheetRow = 0;

        final Iterator i = this.getFilteredSortedRecords().iterator();

        while (i.hasNext()) {

            final Record record = (Record)i.next();

            sheetRow++;

            row = sheet.createRow((short)sheetRow);

            for (int idx = 0; idx < excelColumnCount; idx++) {

                cell = row.createCell((short)idx);

                final Column column =
record.columns[excelColumnIndexes[idx]];

                column.setExcelValue(cell);

            }

        }



        // Write file

        try {

            final FileOutputStream out = new
FileOutputStream(pathPlusFile);

            book.write(out);

            out.close();

        }

        catch (Exception e) {

            e.printStackTrace();

            throw new DataException(e.getMessage());

        }

        return pathPlusFile;

    }



...







Steven M. Nelligan



From: Jon Svede [via Apache POI]
[mailto:[email protected]] 
Sent: Monday, June 20, 2011 8:58 AM
To: Nelligan, Steve M (Facilities & Services)
Subject: Re: Problem creating an .xlsx file using POI and XSSF



Can you send the snippet of code that shows how you are creating/saving
the 
workbook? 

Thanks, 

Jon 





________________________________ 
From: snelligan <[hidden email]> 
To: [hidden email] 
Sent: Mon, June 20, 2011 7:55:23 AM 
Subject: Problem creating an .xlsx file using POI and XSSF 

When i try to create an .xlsx file using POI/XSSF it creates an .xlsx
file, 
but when excel tries to open it, I get the following Error: 
"Excel found unreadable content in 'dkdkd.xlsx' do you want to recover
the 
contents of this workbook?  If you trust the source of this workbook,
click 
Yes." 


When I click Yes I get a pop up which states "Repaired Records:
Worksheet 
properties from /xl/workbook.xml part (Workbook). 

Log returns the following: 
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<recoveryLog 
xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main";><logFi
leName>error031280_01.xml</logFileName><summary>Errors 

were detected in file 
'C:\WINDOWS\TEMP\snelliga-1.xlsx'</summary><repairedRecords 
summary="Following is a list of repairs:"><repairedRecord>Repaired
Records: 
Worksheet properties from /xl/workbook.xml part 
(Workbook)</repairedRecord></repairedRecords></recoveryLog> 

Sorry if this is a duplicate, but looking through the mailing list,
there 
were several with this problem, but I could not find a solution. 

I am using the following Jar files: 
dom4j-1.6.1.jar 
jdom.jar 
log4j-1.2.9.jar 
poi-3.7-20101029.jar 
poi-examples-3.7-20101029.jar 
poi-ooxml-3.7-20101029.jar 
poi-ooxml-schemas-3.7-20101029.jar 
poi-scratchpad-3.7-20101029.jar 
xmlbeans-2.3.0.jar 


This is the first time I have tried to program for POI.  The previous 
programmer used HSSF in the application, but because of office 2010 I am

trying to update to XSSF. 

Any help or direction would be appreciated. 

-Steve Nelligan 









-- 
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/Problem-creating-an-xlsx-file-us
ing-POI-and-XSSF-tp4506461p4506461.html

Sent from the POI - User mailing list archive at Nabble.com. 

--------------------------------------------------------------------- 
To unsubscribe, e-mail: [hidden email] 
For additional commands, e-mail: [hidden email] 

________________________________

If you reply to this email, your message will be added to the discussion
below:

http://apache-poi.1045710.n5.nabble.com/Problem-creating-an-xlsx-file-us
ing-POI-and-XSSF-tp4506461p4506477.html 

To unsubscribe from Problem creating an .xlsx file using POI and XSSF,
click here
<http://apache-poi.1045710.n5.nabble.com/template/NamlServlet.jtp?macro=
unsubscribe_by_code&node=4506461&code=c25lbGxpZ2FAaWxsaW5vaXMuZWR1fDQ1MD
Y0NjF8MjYyNDY3NjE4> . 



--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/Problem-creating-an-xlsx-file-using-POI-and-XSSF-tp4506461p4506501.html

Sent from the POI - User mailing list archive at Nabble.com.

Reply via email to