English 中文(简体)
允许范围外的无效行号(65536) (0.6.5535)
原标题:Invalid row number (65536) outside allowable range (0..65535)

我正在读取文本文件的整数, 把它们作为输入输入查询, 并将查询输出和写入到 xls 文件 。

ResultSet rs;
Connection con = null;
PreparedStatement ps = null;
int person_org_id, external_person_org_id;
File f = null;
Scanner scan = null;

try {
    System.out.println("----------checkpoint-----------");
    Class.forName("oracle.jdbc.driver.OracleDriver");
    System.out.println("----------checkpoint 1-----------");
    con = DriverManager.getConnection("jdbc:oracle:thin:@ksdjf.kjdlk.jkd.com:2222:edb", "aaaaa", "aaaa");
    System.out.println("----------checkpoint 2 ----------");
    if (con == null) {
        System.out.println("unable to connect to database");
    }
    System.out.println("----------checkpoint 3::connected to database---------");
    StringBuffer sql = new StringBuffer();
    sql.append("select abd from edb.abd where customer_id=510 and person_org_id =? ");
    ps = con.prepareStatement(sql.toString());

    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("Excel Sheet");
    HSSFRow rowhead = sheet.createRow(0);
    rowhead.createCell(0).setCellValue("ABC");
    rowhead.createCell(1).setCellValue("DEF");

    f = new File("/tmp/contacts.txt");
    scan = new Scanner(f);
    int index=1;

    while (scan.hasNextInt()) {

        person_org_id = scan.nextInt();

        ps.setInt(1,person_org_id);
        rs= ps.executeQuery();

        while (rs.next()) {                 

            external_person_org_id = rs.getInt(1);

            HSSFRow row = sheet.createRow(index);
            row.createCell(0).setCellValue(person_org_id);
            row.createCell(1).setCellValue(external_person_org_id);
            index++;
        }           

    }   
    FileOutputStream fileOut = new FileOutputStream(new File("/tmp/External_contact_id.xls"));
    wb.write(fileOut);
    fileOut.close();
    System.out.println("--------checkpoint 4:: writing data to xls completed------------");
}
catch (Exception e) {
    System.out.println(e.getMessage());
}

我得到的错误 Invalid 行号(65536)在允许范围外(0.65535)

我的 contacts.txt 文件有大约36000个数字。

最佳回答

HSSF针对的Excel(Excel 2003)版本,最多只能支持65536行。

您可以尝试使用更新的“http://poi.apache.org/spretesheech/index.html” rel=“noreferrer” >XSSF API, 后者支持较晚版本的Excel, 该版本的行数限制更为慷慨。

有一个""http://poi.apache.org/speteshew/converting.html" rel="noreferrer">conversion 指南 ,它能帮助您在两个API之间转换。

问题回答

如果您在文本文件中只有36000项, 一定有其他错误 。

建立一个小样本, 比如说, 100个条目, 然后用它来测试。

仔细查看Excel文件, 如果可以的话。 它看起来像下面的代码是你的问题 :

while(rs.next()){                   

        external_person_org_id = rs.getInt(1);

        HSSFRow row = sheet.createRow(index);
            row.createCell(0).setCellValue(person_org_id);
            row.createCell(1).setCellValue(external_person_org_id);
            index++;
        }       

我只是猜测,但是,如果指数++是在WHILE中,它会促使它每次为每个记录集中的条目创建新行吗?

Excel(也许只有老版)只允许65535行。

http://office.microsoft.com/en-us/excel-help/excel-excel-excel-excel-creditations-and-remits-HP005199291.aspx" rel=“nofolpolt” >link to the Excel 2003 limits, 确实有65535行。2010年,它增加了至

int person_org_id, external_person_org_id;

您需要更改 Int 变量成为整数, 从原始到 -32767 32767 都有限制。

<h:commandButton styleClass="dataExporter"
  value="#{o:translate( Export As Excel )}" style="margin-left:5px">
    <p:dataExporter type="**xls**" target="deviceAuditTable" fileName="DeviceAudit"/>
</h:commandButton>

当您使用 new HSSF Workbook () new XSSF Workbook () 并删除方法调用中HSSF的引用和确保文件扩展名时,这里的 new XSSSFWorkBook () 文件类型为 < 坚固> xlsx

<h:commandButton styleClass="dataExporter"
                            value="#{o:translate( Export As Excel )}" style="margin-left:5px">
    <p:dataExporter type="xlsx" target="deviceAuditTable"
                                fileName="DeviceAudit" />
</h:commandButton>




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...