Hello I would like to know how to fix the error that comes when I create a
file with XSSF XLSX and open the file I get there to repair it.
Also I get the following when I fix it with Microsoft Office Excel 2007.


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="
http://schemas.openxmlformats.org/spreadsheetml/2006/main";><logFileName>error044600_01.xml</logFileName><summary>Se
han detectado errores en el archivo
"F:\Track.xlsx"</summary><additionalInfo><info>Excel ha completado la
validación y reparación en nivel de archivo. Puede que se hayan reparado o
descartado algunas partes de este
libro.</info></additionalInfo></recoveryLog>



Help me please is for a project my code JAVA is as follows:


private int writeXLSX(ReportData rd)
        throws ReportException, IOException
    {
XSSFWorkbook wb = new XSSFWorkbook();
 // create a new sheet
XSSFSheet s = wb.createSheet();
// declare a row object reference
 XSSFRow r = null;
// declare a cell object reference
XSSFCell c = null;

//Report Title
r=s.createRow(0);
c=r.createCell(0);
 c.setCellValue(rd.getReportTitle());

//Report Subtitle
r=s.createRow(1);
 c=r.createCell(0);
c.setCellValue(rd.getReportSubtitle());

 //Report Header
ReportColumn rptCols[]=rd.getReportColumns();
if (ListTools.isEmpty(rptCols)) {
            throw new ReportException("No report columns defined");
        }
boolean useColumnDesc =
rd.getProperties().getBoolean("csvColumnHeaderDescriptions",true);
 DataRowTemplate rdp = rd.getDataRowTemplate();
r=s.createRow(2);
 for (int i = 0; i < rptCols.length; i++) {
            DataColumnTemplate dct =
rdp.getColumnTemplate(rptCols[i].getKey());
            if (dct != null) {
                BodyColumnTemplate bct = this.getBodyColumnTemplate(dct);

                // column title
                String colTitle = null;
                if (useColumnDesc) {
                    HeaderColumnTemplate hct =
this.getHeaderColumnTemplate(dct);
                    colTitle = StringTools.replace(hct.getTitle(rd,
rptCols[i]),"\n"," ");
                } else {
                    colTitle = bct.getFieldName();
                }

                // display column header title
c=r.createCell(i);
 c.setCellValue(colTitle);
            }
        }

// Report body
        int rowsCount = 3;
DBDataIterator data = rd.getBodyDataIterator();
if ((data != null) && data.hasNext()) {
   for(int rcdCount = 0; data.hasNext(); rcdCount++) {
 r=s.createRow(rowsCount);
DBDataRow dr = data.next();
if (dr != null) {
 DataRowTemplate drt = dr.getDataRowTemplate();
        rptCols= dr.getReportColumns();
 for(int i = 0; i < rptCols.length; i++) {
// extract column name/arg
            String colName = rptCols[i].getKey();

            // get field value
            DataColumnTemplate dct = drt.getColumnTemplate(colName);
            if (dct != null) {
                BodyColumnTemplate bct = this.getBodyColumnTemplate(dct);
                String fldName = bct.getFieldName();
                Object fldVal  = dr.getDBValue(fldName, rcdCount,
rptCols[i]);
                String valStr  = (fldVal != null)? fldVal.toString() : "";
 c=r.createCell(i);
c.setCellValue(valStr);
          }
   }
 }
rowsCount++;
   }
 }

for (int i = 0; i < rptCols.length; i++) {
        s.autoSizeColumn((short)i);
        }

ByteArrayOutputStream baos=new ByteArrayOutputStream();
wb.write(baos);
 baos.close();
InputStream in=new ByteArrayInputStream(baos.toByteArray());

        /* MIME type */
        // (See "org.opengts.war.track.page.ReportDisplay:writePage")
        HttpServletResponse response =
rd.getRequestProperties().getHttpServletResponse();
 response.reset();
        CommonServlet.setResponseContentType(response,
HTMLTools.CONTENT_TYPE_XLSX);
 ServletOutputStream out2=response.getOutputStream();
byte[] outputByte=new byte[32768];
 while(in.read(outputByte,0,32768)!=-1){
out2.write(outputByte, 0, 32768);
 }
in.close();
        out2.flush();
out2.close();

return this.rptBody.getRecordCount();
    }

-- 
Atte:

Carlos Jesus Gonzalez Ramos




-- 
Atte:

Carlos Jesus Gonzalez Ramos
Celular: 300 2707873

Reply via email to