Control the Conversion of Large Numeric Value to Exponential Notation, Delete Redundant Spaces from HTML & Detect if a Cell Value Starts with Single Quote with Aspose.Cells for Java 8.8.0

Share on FacebookTweet about this on TwitterShare on LinkedIn

Aspose.Cells for JavaWe are pleased to announce the release of Aspose.Cells for Java 8.8.0. This month’s release includes new features, enhancements and bug fixes that further improve the overall stability and usability of the API. Please check the release notes in order to get an idea about what is new and what has been fixed with this revision of Aspose.Cells for Java. If you are planning to upgrade the API from any previous version, we strongly suggest you to check the Public API Changes section to know what has been changed since your current revision of the API.

While you are downloading the latest build, here is a look at the biggest features in this release.

Control the Conversion of Large Numeric Value to Exponential Notation

As per default behaviour, if a numeric value is larger than the threshold, the API converts such values to exponential notation while importing HTML segment/files to Aspose.Cells object model. In past, we could use the HTMLLoadOptions.ConvertNumericData property to control the conversion of textual values to numeric data, however, this approach has its own drawbacks. For instance, if there are more than one columns containing the numeric values, setting the HTMLLoadOptions.ConvertNumericData property to false will direct the Aspose.Cells APIs to keep all values in textual format. In such case, all formatting from the numeric values will be lost.

In order to handle the situations where users wish to retain the format of all numeric values as well as keep the data in its original state, the Aspose.Cells for Java 8.8.0 has exposed the HTMLLoadOptions.KeepPrecision property. The Boolean type property allows to control the conversion of large numeric values to exponential notation. When set to true, the numeric values larger than 15 digits will be imported as it is.

Here is the simple usage scenario demonstrating the usage of HTMLLoadOptions.KeepPrecision property to avoid the conversion of large numbers to exponential notation while importing data from Html.

//Sample Html containing large number with digits greater than 15
String html = "<html><body><p>1234567890123456</p></body></html>";
//Convert Html to byte array
byte[] byteArray = html.getBytes();

//Set Html load options and keep precision true
HTMLLoadOptions loadOptions = new HTMLLoadOptions(LoadFormat.HTML);
loadOptions.setKeepPrecision(true);

//Convert byte array into stream
java.io.ByteArrayInputStream stream = new java.io.ByteArrayInputStream(byteArray);

//Create workbook from stream with Html load options
Workbook workbook = new Workbook(stream, loadOptions);

Delete Redundant Spaces from HTML

Aspose.Cells for Java 8.8.0 has exposed the HTMLLoadOptions.DeleteRedundantSpaces property to control the preservation of redundant spaces after the line break tag (<BR> tag) in HTML. If the aforementioned property is set to true the API will delete all the redundant spaces while importing the HTML in Aspose.Cells object mode. The HTMLLoadOptions.DeleteRedundantSpaces property has the default value as false, that means, all the redundant spaces are preserved in the resultant spreadsheet.

Detect if Cell Value Starts with Single Quote

Aspose.Cells for Java 8.8.0 has exposed the Style.QuotePrefix property to detect if the cell value starts with single quote mark. With previous revisions of Aspose.Cells APIs, it was not possible to distinguish between the text values such as sample and ‘sample.

Here is the simple usage scenario of Style.QuotePrefix property to find if the cell value starts with single quote mark.

//Create an instance of workbook
Workbook workbook = new Workbook();

//Access first worksheet from the collection
Worksheet worksheet = workbook.getWorksheets().get(0);

//Access cells A1 and A2
Cell a1 = worksheet.getCells().get("A1");
Cell a2 = worksheet.getCells().get("A2");

//Add simple text to cell A1 and text with quote prefix to cell A2
a1.putValue("sample");
a2.putValue("'sample");

//Print their string values, A1 and A2 both are same
System.out.println("String value of A1: " + a1.getStringValue());
System.out.println("String value of A2: " + a2.getStringValue());

//Access styles of cells A1 and A2
Style s1 = a1.getStyle();
Style s2 = a2.getStyle();

System.out.println();

//Check if A1 and A2 has a quote prefix
System.out.println("A1 has a quote prefix: " + s1.getQuotePrefix());
System.out.println("A2 has a quote prefix: " + s2.getQuotePrefix());

Other Enhancements & Improvements

The most notable enhancements in this release are as follow:

Aspose.Cells for Java Resources

The resources, you may need to accomplish your tasks: