Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting worksheet to csv while keeping excel formats (where applicable) #1558

Open
dtrue opened this issue Jan 26, 2024 · 9 comments
Open

Comments

@dtrue
Copy link

dtrue commented Jan 26, 2024

Hi, there! Thanks for such a great library. Quick question - is there any way to preserve formatting when exporting to csv. It looks like in the excel package there is a value and a text field. I'm wondering if there is a way to convert to .csv and being able to use the text version (for say custom formats). Obviously formatting that contains color or whatever wouldn't follow but curious if I can get regular format masks to be exported.

Thanks so much!
Dan

@dfinke
Copy link
Owner

dfinke commented Jan 26, 2024

Thanks for trying ImportExcel.

so if the the Excel sheet has "$1,234.00" that is what you want in the csv?

@dtrue
Copy link
Author

dtrue commented Jan 26, 2024

Yep! Or say a (1,000) instead of -1000. Or if we append some text suffix to a value...such as the value is 2 but the custom format text is 2 days.

@dfinke
Copy link
Owner

dfinke commented Jan 26, 2024

Off the top of my head, I don't recall having that. I'll think about if it is in there. Took a quick scan, didn't see anything.

Need to take a deeper look. If it is not there, will think about how hard to add.

@dtrue
Copy link
Author

dtrue commented Jan 26, 2024

You're awesome! The functionality is to try and replicate if I 'save as' my xlsx worksheet to csv. It prompts me that I'll lose some unsupported stuff (e.g. background color)...but everything else seems to work as expected. Wondering if there is a way to mimic this but obviously without having to click through prompts about saving/losing features.

@dfinke
Copy link
Owner

dfinke commented Jan 26, 2024

Ah, so the save as in Excel when choosing csv, it keeps the $1,235.00?

Without looking at the code I do believe Export-Excel returns the value. I think text has the formatting. Not sure how much.
Not sure how much may break if a param enables returning either one.

@dtrue
Copy link
Author

dtrue commented Jan 26, 2024

Yes observationally it seems to keep all the desired format variations.

@dfinke
Copy link
Owner

dfinke commented Jan 26, 2024

Hey there @jhoneill. I'm mixing up params in my head between Import and Export -excel. There was no switch on Export-Excel to grab the .text of a cell rather than .value?

Time to do a spike test on this.

@jhoneill
Copy link
Contributor

Hey there @jhoneill. I'm mixing up params in my head between Import and Export -excel. There was no switch on Export-Excel to grab the .text of a cell rather than .value?

Time to do a spike test on this.

No ... we're generally sticking number / text / date / boolean and then applying formatting as distinct operation with Export.

Import is bringing each row in as an object so each cell in that row comes in as the number/date/string in .Value which is almost always what we want. Getting .text instead of .value would be easy enough

@dfinke
Copy link
Owner

dfinke commented Jan 27, 2024

@jhoneill thanks, yeah, thinking of adding something like [Switch]$AsText then `$targetProperty = if($AsText) {'text'} else {'value'}.

Hopefully off to the races.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants