ApachePOI Java到Excel单元格空白
我正在尝试使用Java中的ApachePOI将一些结果写入excel文件。我将结果存储在字符串变量中,然后在数据中使用这些变量。打电话。前两种方法效果很好,但第三种方法会产生空白单元格。当我打印到系统时。出来println()显示良好
// Create File to save results
//创建空白工作簿 XSSF工作簿=新建XSSFWorkbook()
// Create a blank sheet
XSSFSheet sheet = workbook.createSheet("Usage");
// Write Header Row (Object[])
Map<String, Object[]> data = new TreeMap<String, Object[]>();
data.put("1", new Object[]{"Set-ID", "Title", "Usage" });
int row = 1;
XML CODE to Navigate Node .....
for (int n = 0; n < childNodes.getLength(); n++) {
Node currentnode = childNodes.item(n);
result += node.getNodeValue();
String NodeName = currentnode.getNodeName();
String NodeText = currentnode.getTextContent();
System.out.println("Child Node Name: " +NodeName);
XML CODE to Navigate Node .....
if (NodeText != null && !NodeText.isEmpty()){
System.out.println("Child Node Text: " +NodeText);
fileWriter.write(";"+";"+NodeText+";");
fileWriter.write(System.lineSeparator());
String line = String.valueOf(t);
data.put(line, new Object[]{ t,SetID,Title,NodeText.trim()});
}
}
try {
// this Writes the workbook gfgcontribute
FileOutputStream out = new FileOutputStream(new File("Usage.xlsx"));
workbook.write(out);
out.close();
System.out.println("Usage.xlsx written successfully on disk.");
}
catch (Exception e) {
e.printStackTrace();
}
我的打印输出如下所示:
Set-Id : babf6fab-d841-4092-88f0-fcf99c4bfa90;
Title : METFORMIN HYDROCHLORIDE TABLET [A-S MEDICATION SOLUTIONS];
Attribute Node Name: code
Attribute Node Value: 34067-9
Parent Node Name: section
Child Nodes: 11
Child Node Name: #text
Child Node Text: Child Node Name: id
Child Node Name: #text
Child Node Text: Child Node Name: code
Child Node Name: #text
Child Node Text: Child Node Name: title
Child Node Text: INDICATIONS AND USAGE
Child Node Name: #text
Child Node Text:
Child Node Name: text
Child Node Text: Metformin hydrochloride tablets are indicated as an adjunct to diet and exercise to improve glycemic control in adults and children with type 2 diabetes mellitus.
当我打开Excel工作表时,我有设置ID和标题的列表,但用法列为空
# 1 楼答案
发现了问题。单元格文本限制为32767个字符,部分文本结果大于此值。一旦我为超过限制的文本添加了一个捕获,它就工作得很好