use of org.apache.poi.ss.util.NumberToTextConversionExamples.ExampleConversion in project poi by apache.
the class NumberRenderingSpreadsheetGenerator method main.
public static void main(String[] args) {
writeJavaDoc();
HSSFWorkbook wb = new HSSFWorkbook();
SheetWriter sw = new SheetWriter(wb);
ExampleConversion[] exampleValues = NumberToTextConversionExamples.getExampleConversions();
for (ExampleConversion example : exampleValues) {
sw.addTestRow(example.getRawDoubleBits(), example.getExcelRendering());
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
wb.write(baos);
} catch (IOException e) {
throw new RuntimeException(e);
}
byte[] fileContent = baos.toByteArray();
replaceNaNs(fileContent, sw.getReplacementNaNs());
File outputFile = new File("ExcelNumberRendering.xls");
try {
FileOutputStream os = new FileOutputStream(outputFile);
os.write(fileContent);
os.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
System.out.println("Finished writing '" + outputFile.getAbsolutePath() + "'");
}
use of org.apache.poi.ss.util.NumberToTextConversionExamples.ExampleConversion in project poi by apache.
the class NumberRenderingSpreadsheetGenerator method writeJavaDoc.
public static void writeJavaDoc() {
ExampleConversion[] exampleConversions = NumberToTextConversionExamples.getExampleConversions();
for (ExampleConversion ec : exampleConversions) {
String line = " * <tr><td>" + formatLongAsHex(ec.getRawDoubleBits()) + "</td><td>" + Double.toString(ec.getDoubleValue()) + "</td><td>" + ec.getExcelRendering() + "</td></tr>";
System.out.println(line);
}
}
use of org.apache.poi.ss.util.NumberToTextConversionExamples.ExampleConversion in project poi by apache.
the class TestNumberToTextConverter method testAll.
/**
* Confirms that <tt>ExcelNumberToTextConverter.toText(d)</tt> produces the right results.
* As part of preparing this test class, the <tt>ExampleConversion</tt> instances should be set
* up to contain the rendering as produced by Excel.
*/
public void testAll() {
int failureCount = 0;
ExampleConversion[] examples = NumberToTextConversionExamples.getExampleConversions();
for (int i = 0; i < examples.length; i++) {
ExampleConversion example = examples[i];
try {
if (example.isNaN()) {
confirmNaN(example.getRawDoubleBits(), example.getExcelRendering());
continue;
}
String actual = NumberToTextConverter.toText(example.getDoubleValue());
if (!example.getExcelRendering().equals(actual)) {
failureCount++;
String msg = "Error rendering for examples[" + i + "] " + formatExample(example) + " " + " bad-result='" + actual + "' " + new ComparisonFailure(null, example.getExcelRendering(), actual).getMessage();
System.err.println(msg);
continue;
}
} catch (RuntimeException e) {
failureCount++;
System.err.println("Error in excel rendering for examples[" + i + "] " + formatExample(example) + "':" + e.getMessage());
e.printStackTrace();
}
}
if (failureCount > 0) {
throw new AssertionFailedError(failureCount + " error(s) in excel number to text conversion (see std-err)");
}
}
Aggregations