Perl - Reformat a column in Excel - excel

Using some combination of Win32::OLE, ParseExcel, WriteExcel...I want to be able to change the formatting of all of the cells in a column (or multiple columns, based on a condition) to be a custom date format, such as "yyyy-mm-dd h".
I have been able to use Win32::OLE to do a find and replace on an Excel file that I have open, but I am not sure the best way to reformat an entire column of cells. I imagine it will be something along the lines of parsing the file with ParseExcel, and using WriteExcel to overwrite the file after changing the format somehow.
Any advice would be greatly appreciated, cheers!

Don't overwrite, copy to a new name (then you can compare, and the process is reversable).
You would essentially copy all the cells, modifying only the ones you need to format change.
Excel Format Info - many examples for formatting time

Related

Delete #NULL! in blank cells

While exporting an SPSS (.sav) data file to excel, the blank cells were imputed as #NULL! .Is there any way to overcome this?
Even, we can replace the #NULL! by find and replace in Excel, but i need to do this in SPSS end itself.
Please assist.
Regards
Satheeshkumar
You may consider saving a copy of your original spss file, and use the syntax command of changing the variables into strings... use alter type command. more details here: http://www.spss-tutorials.com/changing-variable-properties-3-type/
As i wrote, you probably save your file as csv. or excel file. If the variable is a string, it will output with non #NULL!, but when it is a numeric value, and the cell is empty, the excel shows the #NULL! character.
To exclude #NULL, we can export by .csv file, then save as by excel file.
It works.

Excel Save CSV without blanks

I have an Excel spreadsheet that generates CSV scripts used in an application. The scripts must be in a very specific format, and I save a master in XLSX format with protected sheets and data validation to save the CSVs from rather than directly edit the CSVs, as directly editing the CSVs can lead to mistakes.
The issue is that the scripts can be of nearly any length. The left column of each line can only be one of a certain set of values, and the last line has to say "END". The only way I can do this without VBA is the following formula in the A column, from row 7 (the first 6 are header information) to row 1048576 (last Excel row) and protect the sheet with column A locked:
=IF(AND(ISBLANK(B368),NOT(ISBLANK(B367))),"END",IF(ISBLANK(B368),"",A367))
This makes the last row say "END" in column A, and all rows after blank, which is what is desired. The problem is that now when the CSV file is saved, it will always have 1048576 rows, with all the bottom rows containing the delimiters ",,,," . This won't work, the CSV file needs to stop after the "END" row. Is there a way to write the formula that will cause Excel to ignore the cells which evaluate to blank when saving to CSV or an alternate way to save to CSV in Excel that will ignore all the rows that evaluate to blank?
Note: I have a solution in VBA already that I can use on my own machine (it copies the data up to "END", pastes in a new sheet in text only format, then saves as CSV with the name of the original worksheet). I want to share this sheet, however, and getting around the security constraints to share macros at my company is a pain. So I'm looking for a way this might be done without Macros, if it's possible at all.
In looking for an answer I found this link, which is similar, but not the same:
Saving Excel data as csv with VBA - removing blank rows at end of file to save
As the "blanks" I have are active rows because they contain formulas, this method will not work.
Manually deleting the rows / columns will work to reset the size, as GSerg noted in the other question. Alternatively, also as suggested by GSserg, you can copy the data to a new sheet before saving.
Otherwise, an easy fix might be to create a small post-excel / pre-processing script - perhaps using a batch file - Batch / Find And Edit Lines in TXT file - or a similar solution in any small scripting language to remove the extra rows.

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.

Getting formulas out of 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

Programmatically format a date in an excel sheet using Office Open Xml SDK

I'm building an Excel xlsx spreadsheet using the office open XML SDK. I can add dates to the sheet by converting them to their "AO" date representation and setting the Cell Value to number. I can't, however, figure out how to add the dd-mm-yy formatting to the cell.
I've seen a lot of complicated examples where you have to create a stylesheet from scratch, add the format to it and then reference that format, but I figure there must be an easier way. I'm creating my sheet from a template, and Excel already has builtin formats/styles. IMO I should be able to just load the stylesheet from the excel file I'm using as a template and then apply the format. Can't figure out how to do it though.
If you're creating an xlsx from scratch you can't avoid creating the style sheet. You minimally need a style sheet and cell format element. The cell format element can reference a built-in date format in which case you can avoid the custom number format, but if you want a date format that isn't built-in you need a number format element too.
If you're creating an xlsx from a template xlsx, then you can reference a cell format that's already defined, but it can be very sensitive since the references are based only on index, so you are safer looking through the defined cell formats to find the one that matches the date format you want as opposed to hard-coding the cell format index.
Try this - I used it when I was trying to make my own number formats. It's a good example:
Advanced Styling in Excel OpenXML
You will still have to create a style sheet but this is a very good place to start. He has quite a few styles in his as he demonstrates what can be done. Your style sheet could be lots simpler if you only want the one format.
Also have a quick look at the list in this post. Your format may be built into Excel already.
Built in Styles for Excel

Resources