https://issues.apache.org/bugzilla/show_bug.cgi?id=57513

            Bug ID: 57513
           Summary: SXSSF Cell Date Format disappears after 32767 rows
           Product: POI
           Version: 3.11-FINAL
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: SXSSF
          Assignee: [email protected]
          Reporter: [email protected]

Was trying to extract about 50k rows from a database to .xlsx where one column
is formatted as Date and noticed that after 32767 rows Date format disappears. 
It does not matter if you start with rownum 0 or rownum 500, after 32767 rows
formatting disappears. 

-------------------
Code:
package orat_reports;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileNotFoundException;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFDataFormat;

public class SQL_SH_to_XLSX {

    public static void main(String[] args) {
        // TODO Auto-generated method stub

        String url = "jdbc:oracle:thin:@//localhost:1521/orcl";
        String username = "User";
        String password = "Password";

        String sqlQuerry = "Select * from customers";

        // Create new workbook
        SXSSFWorkbook wb = new SXSSFWorkbook();
        Sheet sh = wb.createSheet();
        wb.setSheetName(0, "SQL Test");
        int rownum = 0;

        try{
            Connection con = DriverManager.getConnection(url, username,
password);
            PreparedStatement st = con.prepareStatement(sqlQuerry);
            ResultSet rs = st.executeQuery();

            while(rs.next()) {

                Row row = sh.createRow(rownum);


                    Cell c = row.createCell(0);
                    c.setCellValue(rs.getDouble(1));

                    c = row.createCell(1);
                    c.setCellValue(rs.getString(2));

                    c = row.createCell(2);
                    c.setCellValue(rs.getDate(21));
                    // Date format for cell
                    XSSFDataFormat df = (XSSFDataFormat)wb.createDataFormat();
                    CellStyle cs = wb.createCellStyle();
                    cs.setDataFormat(df.getFormat("dd-mm-yyyy"));
                    c.setCellStyle(cs);

                rownum++;
            }            

        } catch (SQLException e) {
            System.out.println(e.getErrorCode());
        } 

        //Write file
        try {
            FileOutputStream out = new FileOutputStream("SQL Test.xlsx");
            try {
                wb.write(out);
                out.close();
                wb.close();
            } catch (IOException ioe) {
                System.out.println(ioe.getMessage());
            }

        } catch (FileNotFoundException fnfe) {
            System.out.println(fnfe.getMessage());
        }

        System.out.println("Happy Days");
    }

}

-- 
You are receiving this mail because:
You are the assignee for the bug.

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

Reply via email to