both read and write excel formats in R - excel

I'm trying to read an excel file including formatting (cell and text colour, bold, ...) to R, do some editings in the data, and then write it back to excel, including the original formatting. So far, I found R packages to write excel files including formating (openxlsx, xlsx), and also a package which reads excel format (tidyxl). However, I didn't find an easy way to write an excel file with the same formatting that has been read by the R function.
I.e.: the way that tidyxl gathers the format data in an R object is totally different than how openxlsx or xlsx writes it to excel format.
I wonder if anyone knows of something or developed any easy function for this.

Related

Including format instructions in CSV?

I have to write data in a csv format, but some of the users will edit that in excel and those have been complaining about the lack of cell formatting. Is there any way to include some instructions on how excel should format the cells, e.g. the same way you can tell excel the separator with an initial line with SEP=,?

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.

How to get cell formats from XLSX files in Perl?

I am able to find $cell->get_format() or $cell->format _hash in .xls files parser but not for xlsx format. I am also open to use any XLSX parser for reading the spreadsheet. Basically I am copying one spreadsheet to another preserving the format.
I am new to the Perl, Please bear up with me if it's very basic. The below code works fine copying in excel value to another. I am having trouble copying the format. I need to copy the format value from the reading file and then assign it to writing cell- self is the variable need to change.
The question I have asked Earlier
How to copy the format of the .xlsx cell using "Excel::Writer::XLSX" reader to the copied cell using "Spreadsheet::WriteExcel" writer?
And I am open to any other XLSX parser in case this is not the right to copy the format of the cell.
These modules cannot modify spreadsheets in place, so you need a reader and a writer. To read an XLSX file, use Spreadsheet::ParseXLSX which implements the same methods as Spreadsheet::ParseExcel but parses XLSX files, so its cells also have get_format which returns the properties listed here. To write a new spreadsheet use Excel::Writer::XLSX, which implements the same methods as Spreadsheet::WriteExcel but creates XLSX files. You would add formats to such a new sheet as described here.

Automate opening and formatting of csv file in unix

My requirement is as follows:
Open an input csv file in spreadsheet in unix (like ooffice)
Post process the excel for following requirements:
Post process a column such that fields with number less that 0 appear as red
Put filters on top of each relevant columns (As we can do in Microsoft excel)
save the file in .xls (or any other format) such that when opened in microsoft excel, the data formatting is not lost.
The above automation requirement is part of my flow. Though I am familiar with scripting, I have never worked on such requirement.
Will really appreciate your help.
Here is a solution using csv2odf that should get the result you want:
Create a spreadsheet template in Excel or OpenOffice with these specifications:
Insert column titles with the same number of columns as the csv. (If you want to use titles from the csv file, add the -H option to the command below.)
Add one sample row of data. Use dummy numbers where numbers will go and dummy text where text will go. Format the text/numbers however you want, including conditional formatting to make negative numbers red.
Save the template as xlsx or ods (xls will not work).
Run this command:
csv2odf yourdata.csv yourtemplate.xlsx output.xlsx
Your data will be inserted into the template and the formatting will be duplicated on each row.

Using Excel Macros in both XLS and XLSX

How can i use the same macro in both the XLS and XLSX formats?
Is there anyhthing to be added in the XLSX format. i have written a small macro in XLSX (it has last column XFD) i want to use it in the XLS (it has last column as IV) .Is there anything to be changed?
This question is not about converting the file formats.
XLSX provides a broader set of formulas and also VBA functionality. Additionally, XLSX expands the row/column restriction that exists before Excel 2007 (from 256 columns to 16,384).
If your macros are written using up to column 16,384 (XFD), you're going to have to perform the calculations in chunks to make them fit within the 256 column (IV) restriction of Excel 2003. If you're using variables and not writing everything to a sheet, then there should be no problem (barring running out of memory).
Without more detail, it's difficult to tell whether you're using a set of functions from Excel 2007 that may not be supported in Excel 2003.
Which format was it written first? normally it should work in both formats of excel. As you are referring to last cell of both formats, it seems to have a code level issue than a version lavel.

Resources