I am exporting results of an SQL query where all the fields are varchar strings. Fields such as serial numbers which may or may not contain letters, building numbers, and room numbers that should retain all their characters in order to be of any use in the report. For example, Serial number 0129306201100910 gets truncated to 1.29306E+14 making it useless data. Here is the code I am using in order to do the actual writing of the export. Any suggestions on how to modify this in order to keep leading zeroes and stop the scientific notation truncation? Thanks in advance.
wr.write("\"Inventory_No\",\"Building_No\",\"Actual_Building\",\"Room_No\",\"Actual_Room\",\"CDDEPT\",\"Location\",\"Actual_Location\",\"Normalized_MFG\""
+ ",\"Manufacturer\",\"Normalized_Model\",\"Model\",\"Serial Code\""
+ ",\"Cost\",\"Account_No\",\"Active\"");
wr.newLine();
int count = 0;
while (rs.next()) {
count += 1;
if (count % 1000 == 0) {
wr.flush();
response.flushBuffer();
}
wr.write("\"" + rs.getString("Inventory_No") + "\",");
wr.write("\"" + rs.getString("Building_No") + "\",");
wr.write("\"" + rs.getString("Actual_Building") + "\",");
wr.write("\"" + rs.getString("Room_No") + "\",");
wr.write("\"" + rs.getString("Actual_Room") + "\",");
wr.write("\"" + rs.getString("CDDEPT") + "\",");
wr.write("\"" + rs.getString("Location") + "\",");
wr.write("\"" + rs.getString("Actual_Location") + "\",");
wr.write("\"" + rs.getString("Normalized_MFG") + "\",");
wr.write("\"" + rs.getString("Manufacturer_Name") + "\",");
wr.write("\"" + rs.getString("Normalized_Model") + "\",");
wr.write("\"" + rs.getString("Name") + "\",");
wr.write("\"" + rs.getString("Serial_Code") + "\",");
wr.write("\"" + rs.getString("Cost") + "\",");
wr.write("\"" + rs.getString("Account_No") + "\",");
wr.write("\"" + rs.getString("Active") + "\",");
wr.newLine();
}
Make sure your csv writer formats the cell as “Text” which will write it as text disabling scientific notation.
In case you double click on your cell you should be seeing the full value with your current code.