date value is converted from dd-mm-yyyy to dd/mm/yyyy while converting excel to html using aspose.cells for java - aspose-cells

I have a cell in excel formatted as date with value '31-03-2017' but when I am exporting the excel to html it is getting converted to '31/03/2017'.
'03-31-2017' again a date formatted cell but coming up as expected, if I have to speculate looks like there is a problem with dd-MM-yyyy format.
I am using "aspose-cells-8.7.0" library.
Any help is highly appreciated.
Code snippet
Workbook workbook = new Workbook(new FileInputStream(new File("filePath")));
workbook.calculateFormula();
HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions();
htmlSaveOptions.setPresentationPreference(true);
htmlSaveOptions.setParseHtmlTagInCell(false);
htmlSaveOptions.setExportHiddenWorksheet(false);
workbook.save("outputPath", htmlSaveOptions);

Such issue occurs because of Language and Region Settings of your machine i.e. OS (Operating System). Please see the following screenshot. You can change your region and country and number and date formats from such interfaces.
Now, whenever you will change your region or language, your dates will look different because your dates are in built-in formats and they don't have custom formats.
In order to test this, please change the region and open your Excel file in Microsoft Excel and you will see, your dates now look different.
It means, you should load your workbook with the correct region and language settings. Here is the sample code for your reference. Please read its comments.
Java
//Please load your workbook with correct Language and Region - Country Code
LoadOptions loadOptions = new LoadOptions();
loadOptions.setLanguageCode(CountryCode.USA);
loadOptions.setRegion(CountryCode.USA);
//Pass the load options while loading workbook
Workbook workbook = new Workbook(new FileInputStream(new File("filePath")), loadOptions);
Note: I am working as Developer Evangelist at Aspose

Related

Format an excell column as link (ClosedXML generated file)

i generated an excel file with ClosedXML library
XLWorkbook wb = new XLWorkbook();
wb.Worksheets.Add(dt,"aaaaa");
wb.SaveAs("aaaa.xlsx");
one column of the datatable contains a link (a string with a valid url), the generated excel file doesn't show the columns as link but as a normal string.
How may i format this column in order to make possible click on it?

MS Access 2013 saved exports not saving to MSysIMEXSpecs table

I am working on an Access 2013 database that someone else created. It has a module that exports several reports as PDF files to a specific folder. Some of the reports are exporting successfully but 3 of them aren't. An example of the code used is as follows:
DoCmd.RunSavedImportExport "Export-rptJobsToClose_FS2"
I receive an error that the database can't save the output data to the file you've selected. I realize that the path is saved in the "Export-rptJobsToClose_FS2" saved export. I would like to see the path so I have tried opening the MSysIMEXSpecs table but when I do, it is totally empty. So is the corresponding table MSysIMEXColumns. If I create a new SavedExport definition and use the same name as the one in the code, I get the message that it already exists. How is that possible that it already exists when those system tables are empty? I have tried creating saved exports with new names, but if they don't work I can't reuse those names as I get the message that they already exist. So, I have to keep thinking of new names and can't see any information about the Saved Exports that I have already created. Thanks for any help.
MSysIMEX* tables contain import specifications for correct data transfer. Saved import-exports stored in other place. You can see all names of saved imports/exports using menu External Data -> Saved Imports/Exports, there you can also see and edit destination path and import/export name.
Thru VBA you can reach the collection of saved imports/exports by using collection CurrentProject.ImportExportSpecifications, destination path stored in XML attribute of each Item.
The code below prints all existing import-export specifications
Dim ie As ImportExportSpecification
For Each ie In CurrentProject.ImportExportSpecifications
Debug.Print ie.Name
Next
Saved import/exports in Access are not the same thing as import/export specifications. If you want to see the saved import/export definition, you can dump it by typing the following command into the Immediate window.
? CodeProject.ImportExportSpecifications(*SpecificationName*).XML

Add validation to entire column

In my current project I need to create an excel file with a list validation on an entire column. Googling turned up with the following two results:
http://www.aspose.com/docs/display/cellsnet/Working+with+Validations+in+Columns
This refers to aspose.cells.griddesktop which actually has the worksheet.Columns[n].Validations property. Aspose.Cells doesn't.
http://www.aspose.com/docs/display/cellsjava/Data+Filtering+and+Validation
All the examples use a CellArea which requires a start- and end row.
Anything I missed?
There are two types of excel formats. One is older XLS format and other is newer XLSX format. The number of rows inside the column in XLS format is 65536 and in XLSX format is 1048576. So you can use the above two values to cover your entire column in the CellArea.
You can also use CellArea.CreateCellArea() static method to create cell area object easily
For XLS format, the following CellArea code covers entire column A
CellArea ca = CellArea.CreateCellArea("A1", "A65536");
For XLSX format, the following CellArea code covers entire column A
CellArea ca = CellArea.CreateCellArea("A1", "A1048576");
Note: I am working as Developer Evangelist at Aspose
Here is another way to cover entire column.
// Cover entire column A
CellArea ca = CellArea.CreateCellArea("A", "A");
This will work with both XLS and XLSX format.
Please see the following sample code, execute it at your end and also read its comments. You will get two output Excel files. One in XLS format and other in XLSX format.
Now enter 200 (or any value greater than 100) in these cells and you will get validation error.
A65536
A1048576
C#
// Create workbook
Workbook workbook = new Workbook();
// Accessing the Validations collection of the worksheet
ValidationCollection validations = workbook.Worksheets[0].Validations;
// Cover entire column A
CellArea ca = CellArea.CreateCellArea("A", "A");
// Creating a Validation object
Validation validation = validations[validations.Add(ca)];
// Setting the validation type to whole number
validation.Type = ValidationType.WholeNumber;
// Setting the operator for validation to Between
validation.Operator = OperatorType.Between;
// Setting the minimum value for the validation
validation.Formula1 = "10";
// Setting the maximum value for the validation
validation.Formula2 = "100";
// Save in XLS format
workbook.Save("output.xls", SaveFormat.Excel97To2003);
// Remove the area of validation and add it again
validation.RemoveArea(ca);
validation.AddArea(ca);
// Save in XLSX format
workbook.Save("output.xlsx");
Note: I am working as Developer Advocate at Aspose

Exporting BIRT report into CSV

I am Using BIRT for reporting in my project.
The report shows correct value for amount(String) as 123456789123, but when i try to export the same report into csv, the csv file shows same amount as 1.234E11.
I want to value as 123456789123 in csv too.
Please help
Thanks
I imagine this is probably an issue with viewing it in Excel. Exporting data does not export format codes. Open the csv in notepad and you will see the correct data. If you export the report to excel you can set a custom format code like #####0 in the Format Number property in the properties editor for the data item.
If the number is too large excel will display the value like that. If you expand the column and set the column to number under format cells it will display correctly. You will need to save it as an excel workbook.
We just had this problem with the our BiRT reporting tool. When we opened the exported file in a text editor the number was formatted in scientific notation. This was a bug with one of Birt's custom formatters.
We had to look at org.eclipse.birt.report.engine.dataextraction.impl.CommonDataExtractionImpl and change the line
valueFormatters[i] = new NumberFormatter( patterns[i], this.locale );
to
String pattern = patterns[i] == null ? "Unformatted" : patterns[i];
valueFormatters[i] = new NumberFormatter( pattern, this.locale );
Setting the pattern to "Unformatted" made default format stay as a normal integer rather than scientific notation (via a decimal formatter).

Formatting csv files in Excel

Win XP, Excel 2007
I know there are various other posts on csv formatting but couldn't quite find what i needed.
Some of our data is held off site by another company and they send us a csv file every morning with the previous days data.
The problem is this data has come from web input forms that may have drop-down lists.
For example there may be a drop down list of Number of Employees with options like 1-10, 11-25, 26-50 etc
When we open the csv file in Excel certain options like 1-10 has been turned into Oct-01 date format which we do not want.
Is there an easy way to change these back OR reformat the cells and do a find...replace? (This didn't seem to work terribly well as it kept reverting back to the date)
Indeed is there a better way of opening the csv file to keep the formatting intact? and save us doing lots of find...replaces.
Ultimately we will need to open the csv in Excel though.
Grateful for any hints
Isn't that SO annoying? Here's how I deal with this issue:
When you open the CSV file in Excel, you should get a dialog with parsing options. First you select delimited or fixed then you get a screen that previews the data parsing.
It's easy to miss, but in the upper right corner of the dialog box there's an option to set a specific data format for each column. Select the column you want to protect and set the format to text. (This keeps Excel from dropping the leading zeros in ZIP codes for New England too!)
Once you get it into Excel, you can do a vlookup or replace to reset the values to your own codes.
Hope this helps. Good luck.