Getting formulas out of Excel - excel

I have a spreadsheet that I need to convert into code. Is there a way to export the spreadsheet that keeps the formulas intact?
When I save it as any other format it converts the formulas to their values. For example, if I had =(4/2), the CSV would just put 2. Whereas I need the original formula. I have tried accessing the spreadsheet using PHP Excel also but it cannot load the spreadsheet due to size.

Simplest way is to do CTRL+` and then copy+paste to Notepad or wherever you want

Related

Spire When Pdf-ing an excel file it leaves some formulas as System.Object[][]

I have an excel template that has preset formulas, then have my wpf application fills in data in other sheets then the preset formulas takes the data from the other sheet and shows it on the main page.
The problem is when I automatically PDF the excel most formulas go through but other's give me a System.Object[][] or some other errors. But when I access the excel file with the dataset it works.
The difference between the formulas that go through and the ones that don't are the ones that have an if() statement to remove all non zeroes in a range like this.
=TEXTJOIN("
", TRUE, TEXT(IF(Details!O:O>0,Details!O:O,""), "HH:MM"))
Functions like this works:
=TEXTJOIN("
",TRUE,Details!D:D)
How do I get Spire.xls to PDF the right format?
As you tested the Excel file and found it working fine, the problem is likely located inside the Spire rendering.
You can of course report a bug over there but that might not get resolved instantly.
You may want to try applying a number format to the cells for zero values instead of using that if part in the formula.
Something like this could do when writing with ClosedXML if implemented correctly by Spire:
worksheet.Cell(row, column).Style.NumberFormat.Format = "#,##0;[Red]-#,##0;\"\";#";
Formating possibilities are somewhat documented by Microsoft, take a look over there.

How to format a formula in Microsoft Excel to be in percentage format DIRECTLY in the CSV source file

The problem:
For example, my CSV data is like so: ['=B3/B5'] which displays 0.1 in my Excel sheet but I need it to produce 10%.
I need to be able to fix this from the CSV source data because I'm exporting a CSV file from my website so that means no excel formatting to percentages as I need it to work out of the box for users.
Preferably the solution should be able to support Excel 2007. Google Sheets has a =to_percent(B3/B5) function which works well but I need the equivalent for Excel 2007.
I had a look at this answer: https://superuser.com/questions/318420/formatting-a-comma-delimited-csv-to-force-excel-to-interpret-value-as-a-string
But doesn't seem to directly address the problem.
You could use =B3/B5*100&"%"
Note that this will not be saved as a number (ex. 22.1%) rather as text, because you can't use number formats in a CSV file.

Problems viewing large numbers in Excel (Scientific Notation) in 'Text' formatted cells

I'm having a problem and havnt managed to find a solution online and was hoping I'd get lucky and someone could help.
I have a database application that exports a large dataset to .xlsx
A VBA application then maps this data into another Excel application.
When the data is exported out of the original database application, this process is outside of my control. All the cells have a 'General' cell format and we have some large numbers such as 172627108914 which is the serial number for a piece of equipment. In the exported xlsx file, this serial number is represented as 1.72627E+11.
The next stage of the process copies this data into another worksheet which has all cells formatted as text. The value is copied over but the value stays the same and the format of the cell changes from Text to General.
Does anyone know what I have to do to change to remove the scientific notation?
I'm using Microsoft Excel 2010.
Thanks
Append a single apostrophe to the front of the number. That will force Excel to read the number in 'text' format automatically, and the apostrophe will not show up at the front of the number when it's displayed.
Thanks for the help everyone, in the end some VBA code was written to convert all fields in the original export to text then iterate over each cell and rewriting the value from the formula line. This has resulted in a correctly formatted worksheet to pass to the second application

How to export spreadsheet to CSV without evaluating formulas

I'm looking for a way to export a spreadsheet (from MS Excel or LibreOffice Calc) without evaluating formulas so the formulas are stored in the CSV. I know, for example, I could convert formulas to text in MS Excel prior to export, but don't want to modify the formulas. It appears the default behavior for CSV export in MS Excel loses the formulas if they're not displayed as text.
First, select the tab with the formulas, then hold "Ctrl" + "~" (the tilde character), then do a File, Save As, and choose .csv.
I tried this and opened the file up in notepad, and the formulas were intact.

How to export cells with links, when saving to a csv?

I am trying to export an Excel file (.xlsx) to a csv, with LibreOffice. Some columns have hyperlinks, which I can open when the sheet is open in LibreOffice. The cell does not show the link, but a short summary text: the link is somehow a property of the cell (or the text, not sure).
I would like that the CSV contains the links for the affected columns (I don't care about the short summary text), but by doing a "Save As csv" I am losing the links. What can I do?
EDIT
I have investigated a bit: the hyperlink can be manually created in Libreoffice in a cell with Ctrl-K or from the menu Insert -> Hyperlink. When I try to export the csv, I am offered two relevant options:
save cell content as shown
save cell formulas instead of calculated values
I have played around with them, but those are not helping at all.
Is there any way of exporting the hyperlinks instead of the text?
From what I can tell, the CSV export filter always saves the link text, not the link URL. This behavior occurs when saving from LibreOffice format as well, so your question does not need to involve Excel or the .xlsx format.
What I would probably do is write a macro to create a CSV file with the URLs. If you want to try that, then have a look at https://wiki.openoffice.org/wiki/Documentation/DevGuide/Accessibility/XAccessibleHyperlink.
Depending on what you are trying to do and how much time you are willing to invest, you can create your own filter.
Another option that requires programming would be to use the HTML export filter, which saves both the link text and link URL, and then write some code to parse out the URL.

Resources