[英]Not able to view ComboBox in Excel using JXL API
我正在尝试使用以下代码在JXL API中显示ComboBox:
ArrayList<String> arrList = new ArrayList<String>();
arrList.add("DropDown1");
arrList.add("DropDown2");
arrList.add("DropDown3");
WritableCellFeatures cellFeatures = new WritableCellFeatures();
cellFeatures.setDataValidationList(arrList);
Blank b = null;
Label checkLabel = null;
for (int x = 0; x < xlData.size(); x++) {
for (int i = 0; i <= 14; i++) {
System.out.println("X:" + x + "I:" + i);
if (i > 9) {
checkLabel = new Label(i, x + xlHeader.size(),(String) arrList.get(0));
//b = new Blank(i, x + xlHeader.size());
//b.setCellFeatures(cellFeatures);
checkLabel.setCellFeatures(cellFeatures);
writableSheet.addCell(checkLabel);
System.out.println("Combo Cell : " + x + ":" + i);
}
}
}
我已经尝试过“空白”单元格和“标签”。 但是,Excel仍未显示ComboBox。
将工作表和单元格添加完毕后,请在工作簿上调用write(),然后关闭文件。 最后一步生成输出文件(在这种情况下为output.xls),可由Excel读取。 感谢这个出色的教程,它需要添加:
copy.write();
copy.close();
根据我的测试,此代码可以正常工作:
WritableCellFeatures cellFeatures = null;
Label checkLabel = null;
for (int x = 0; x < xlData.size(); x++) {
for (int i = 0; i <= 14; i++) {
System.out.println("X:" + x + "I:" + i);
if (i > 9) {
checkLabel = new Label(i, x + xlHeader.size(), (String) arrList.get(0));
cellFeatures = new WritableCellFeatures();
cellFeatures.setDataValidationList(arrList);
checkLabel.setCellFeatures(cellFeatures);
writableSheet.addCell(checkLabel);
}
}
}
// All cells modified/added. Now write out the workbook
workbook.write();
workbook.close();
根据我的测试,此代码也可以正常工作:
WritableCellFeatures cellFeatures = null;
Blank b = null;
for (int x = 0; x < xlData.size(); x++) {
for (int i = 0; i <= 14; i++) {
System.out.println("X:" + x + "I:" + i);
if (i > 9) {
b = new Blank(i, x + xlHeader.size());
cellFeatures = new WritableCellFeatures();
cellFeatures.setDataValidationList(arrList);
b.setCellFeatures(cellFeatures);
writableSheet.addCell(b);
}
}
}
// All cells modified/added. Now write out the workbook
workbook.write();
workbook.close();
.xls
,则可能需要另存为.xlsx
才能看到该组合。 我遇到了在Excel2010 / 2013之前打开.xls的情况,即使单元格实际上包含一个数据验证列表并且验证约束起作用,数据验证箭头也丢失了; 如果要查看箭头和组合框,则需要另存为新格式。
而且,这个缺点似乎是由最近的Excel版本而不是JXL引起的,这一事实表明,在OpenOffice.org Cal 3.4.1中打开.xls不会有任何问题,并且该组合可以正常工作。 这可能与以下事实有关:我用于测试的当前版本jxl 2.6.12 2009-10-26 生成Excel 2000格式的电子表格
任何想要改进或使用它的人都可以使用为此答案开发的Java代码 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.