openTable

打开指定的表格,并返回 Table 对象。

语法:

public Table openTable(java.lang.String name)
              throws java.lang.Exception,
                     java.io.IOException

参数:

name - 由开发者在打开文档时自由定义,一般命名为数据库里数据表的名字,代码易于理解。请参考 com.zhuozhengsoft.pageoffice.excelwriter.Table.SubmitName 属性学习如何给Table定义一个 SubmitNameSubmitName 对大小写敏感。

返回:

返回 Table 对象。

抛出:

java.lang.Exception

java.io.IOException

示例:

下面的示例展示了如何调用 openCell 方法获取指定单元格的值。

 Workbook wb = new Workbook(request, response);
 Sheet sheet1 = wb.openSheet("sheet1");
 //获取单元格的值
 String strCompanyName = sheet1.openCell("CompanyName").getValue();
 //获取表格的数据
 Table table1 = sheet1.openTable("SalesInfo");
 while (!table1.getEOF()){
                String strValues = "";
                if (!table1.getDataFields().getIsEmpty()){
                        for (int i = 0; i < table1.getDataFields().size(); i++)
                                strValues = strValues + table1.getDataFields().get(i).getValue() + "&nbsp;&nbsp;";
                        // 把获取到的数据直接输出到当前保存页,在下面 showPage 弹出的对话框里显示保存结果
                        out.println(strValues + "<br>\r\n");
                }
                table1.nextRow();
 }
 table1.close();
 out.println("table1.RowCount = " + table1.getRowCount());
 wb.showPage(800, 600); // 保存成功后弹出对话框显示获取的表格数据
 wb.close();
另请参见:

Table.setSubmitName()方法中的示例代码。

results matching ""

    No results matching ""