Format an excell column as link (ClosedXML generated file) - closedxml

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?

Related

Unable to match csv column name using load records from file

I have created a new screen where I'm uploading Amazon orders from a CSV file. The original CSV file downloaded needs to have the first few lines removed to have the column headings at the top.
Before
After
I have a data field on the screen called date/time, but when I upload the CSV the mapping finds some sort of hidden characters in the file so the mapping doesn't automatically map the field.
I have tried changing the encoding while uploading the file, as well as changing the display name to include the ??? and double quotes like the image below, but the field doesn't auto-map.
Is there someway to get the field to auto-map on the file upload so the user doesn't have to map the field manually?
Thanks,
Kurt Bauer

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

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

phpMyAdmin Import Excel spreadsheet with date and time

I have a Excel file (.xlsx) and I am trying to import it using phpMyAdmin.
(not using .csv)
In the Excel file I have in the first row the headers of the fields from my table and the rest of the rows is the data I want to import like below..
As you can see Colum B contains the date and time. (yyyy-mm-dd hh:mm:ss)
In phpMyAdmin I have the table set up as the following:
When I now go to the 'Import' section to import the Excel file I selected the following:
I then clicked on 'Go' to import the file.
When I do that the date & time field converted to a number like the following:
Am I doing something wrong? How can I make it so that the date & time is the same as per the Excel file ?
In Excel I did format that cell to be custom yyyy-mm-dd h:mm:ss
Any ideas on why this is not importing correctly ?
(I did try saving the file as .xls but got the same result.)
The spreadsheet is preserving the data in its original format when saved and the cell format is loaded separately after that. Obviously phpmyadmin doesn't pick up this trap and loads the formatted data.
Saving your sheet as a CSV should work. You can open the CSV in notepad to confirm that the CSV version contains the correct date format.
It will work if you save file as
OpenDocument Spreadsheet(.ods) from Excel
and importing into phpMyAdmin with OpenDocument Spreadsheet format.

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

Can I use SpreadsheetGear to read from a CSV file without it formatting the cells?

Given a simple CSV file that consists of a string of digit characters and a date in UK format:
"00000000","01/01/2014"
and code to get the used cells:
IWorkbookSet workbookSet = SpreadsheetGear.Factory.GetWorkbookSet();
IWorkbook workbook = workbookSet.Workbooks.Open(#"C:\file.csv");
IRange cells = workbook.Worksheets[0].UsedRange;
when I access cells[0,0].Text it gives it as 0, because it's treating it as numeric and therefore the leading 0s are meaningless. It will do the same for the date. I'm trying to manually construct a DataTable from the cells, but I need the original values in the file.
I tried:
SpreadsheetGear.Advanced.Cells.IValues cells = (SpreadsheetGear.Advanced.Cells.IValues)workbook.Worksheets[0];
var sb = new StringBuilder();
cells[0,0].GetText(sb);
but nothing is appended to the string builder.
How can I get access to the original file values?
SpreadsheetGear does not make available the original values as found in in the CSV file (such as "00000000" in your case). You would only be able to access cell data after it has been parsed and processed by SpreadsheetGear (i.e., converting the above to a double value of 0). If you need the CSV's original values, then you'll need to open up file yourself and manually process and parse it.
It sounds like you ultimately want a DataTable, but if you still require to create a workbook file from your CSV data, once you've created a routine to manually open and parse each "cell" in your CSV file, you could enter each value into a spreadsheet as Text, so that it is preserved as it is found in the CSV file. You can go about this in two ways:
1) Set IRange.NumberFormat to "#", which will treat any future input into that IRange as Text. Example:
worksheet.Cells["A1"].NumberFormat = "#";
worksheet.Cells["A1"].Value = "00000000";
2) Prepend your inputted value with a single apostrophe, which indicates that you want the input to be treated as text. Example:
worksheet.Cells["A1"].Value = "'00000000";
If you still need a DataTable at this point, you could use the IRange.GetDataTable(...) method to accomplish this. Because the cell data is stored as Text, your DataTable values should also reflect these same values Example:
DataTable dt = worksheet.Cells["A1"].GetDataTable(GetDataFlags.None);
(There is a GetDataFlags.FormattedText option, but this isn't really relevant for your case since the cell data is stored as text anyway and so won't be formatted)