Splitting up an Excel file but preserve formatting #1401
Unanswered
jdenicola-pa
asked this question in
Q&A
Replies: 2 comments 4 replies
-
Lot's of work to go after those details. I didn't tackle it. Here is just the font info for a single cell. Does not include alignment, cell color, borders, etc, etc, etc. $data = ConvertFrom-Csv @"
Region,State,Units,Price
West,Texas,927,923.71
North,Tennessee,466,770.67
East,Florida,520,458.68
East,Maine,828,661.24
West,Virginia,465,053.58
North,Missouri,436,235.67
South,Kansas,214,992.47
North,North Dakota,789,640.72
South,Delaware,712,508.55
"@
$xlfile = ".\spike.xlsx"
Remove-Item $xlfile -ErrorAction SilentlyContinue
$excel = $data | Export-Excel $xlfile -PassThru
Set-ExcelRange -Worksheet $excel.Sheet1 -Range "A1" -Bold -FontSize 18
Close-ExcelPackage $excel
$excel = Open-ExcelPackage $xlfile
$excel.Sheet1.Cells["A1"].Style.Font
Close-ExcelPackage $excel
|
Beta Was this translation helpful? Give feedback.
4 replies
-
I don't have docs for the Excel Object Model itself. You can search for VBA | EPPlus | set a breakpoint in your script and inspect the methods/properties by printing them
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have an Excel file (which gets generated by a reporting system).
It looks something like this:
Customer Information
rows for customer 1
totals
Customer Information
rows for customer 2
totals
Customer Information
rows for customer 3
totals
and so on
The "Customer Information" is a literal string that begins each section for a new customer.
I need to split this file into multiple files so that each customer is in its own file.
I wrote some code to do this, to just iterate over the rows and find the start row of "Customer Information" and the row of the next "Customer Information" and pipe the range of $startingRow and $endingRow | Export-Excel, each to a different file.
But of course what gets lost is any formatting. While I can try to reproduce the formatting manually, it's relatively complex. Font size changes, font weight changes, column width and row height changes.
Is there a way to read these attributes from the Excel file? I know I can set them, but I didn't see a way to read them.
Another way I had thought of was to get the start/end of each customer, then for each customer, copy the Excel file, load it using Open-ExcelPackage and delete the rows before and after the rows that I want, then close it to save it. But can rows be deleted after loading with Open-ExcelPackage?
Any other ideas?
Beta Was this translation helpful? Give feedback.
All reactions