I'm trying to write some results to an excel file using Apache Poi in Java. I'm storing the results in String variables and then using those in the data.put call.The first two work fine but the third is resulting in blank cells. When I print to system.out.println() it displays fine ?
// Create File to save results
//Create Blank workbook XSSFWorkbook workbook = new 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();
}
And my print output looks like this:
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.
When I open the Excel sheet I have the list of Set-IDs and the Titles but the usage column is blank?
apache poi
. Or where do you think your code callsapache poi
classes and methods? What isdata.put
doing? And where ist
coming from? – Axel RichterXSSFSheet sheet
? All I can see now is that you not seems to know what your code does at all. As often only copy/pasted code together and now wondering why it not works. – Axel Richter