-
Notifications
You must be signed in to change notification settings - Fork 404
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
Formatting weirdness when adding rows to a table #1666
Comments
took a quick look. leaving this hear for later review. ImportExcel/Public/Export-Excel.ps1 Line 161 in dc4a5e9
|
Hello, you need to add -tablestyle medium2 to preserve the same. For some reason the script when you use -table has the pink table style. So your code should look like this: |
Small update |
Thank you @arkoudigr. @sba923 does that work for you? |
Well, I've tried adding data to two different tables with different formatting, this gets me a corrupted file Excel complains about.... Copy-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath 'test.xlsx') -Destination (Join-Path -Path $PSScriptRoot -ChildPath 'modified.xlsx')
$newrows = @(
[PSCustomObject]@{
A=10
B=11
C=12
},
[PSCustomObject]@{
A=20
B=21
C=22
}
)
$newrows | Export-Excel -Path (Join-Path -Path $PSScriptRoot -ChildPath 'modified.xlsx') -WorksheetName 'Sheet1' -Table 'Table1' -TableStyle Custom -Append
$newrows | Export-Excel -Path (Join-Path -Path $PSScriptRoot -ChildPath 'modified.xlsx') -WorksheetName 'Sheet1' -Table 'Table2' -TableStyle Custom -Append |
Well, the idea you suggest cannot work as it seems. Your excel file gets corrupted because the script add rows and changes the table structure. What I mean is while changing table1 it destroys table 2. Here is something interesting, when I Import test.xlsx to powershell it returns only the first table PS C:**\Downloads\AddRowsToTable202501212100> $test A B C 1 2 3 |
I was just trying to test how one would modify an existing table by name while preserving its format, so I created a sheet with two distinct tables. @dfinke the module should never create a corrupted file, don't you think? |
Sure, can you provide a simple repo of that. It could be that the EPPlus lib may have caused it and fixing that is not likely. Also, no reports on that and if it does, folks find work arounds. |
The repro code in in the zipfile I posted here yesterday. I presume you want me to create a separate issue for that corruption issue, correct? |
not necessarily. what is the corruption? usually if I see a "corruption" when I open the xlsx and it says it has an issue and it will try to recover. |
First if I choose the XML repair log reads: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error523200_01.xml</logFileName>
<summary>
Errors were detected in file
'https://d.docs.live.net/6c0f5f708f464f30/CloudOnly/ImportExcel/AddRowsToTable/modified.xlsx'</summary>
<removedFeatures>
<removedFeature>Removed Feature: AutoFilter from /xl/tables/table1.xml part (Table)</removedFeature>
<removedFeature>Removed Feature: Table from /xl/tables/table1.xml part (Table)</removedFeature>
<removedFeature>Removed Feature: AutoFilter from /xl/tables/table2.xml part (Table)</removedFeature>
<removedFeature>Removed Feature: Table from /xl/tables/table2.xml part (Table)</removedFeature>
</removedFeatures>
</recoveryLog> The file (available in the zipfile I posted yesterday) is very badly damaged:
|
Looked at, will at it some more. Not sure I will be able to fix that. |
Start with an Excel table that looks like this:
If you try to add two more rows to the table using
You'll get a new formatting for the extended table:
Removing the
-Table 'Table1'
parameter preserves the formatting:Code, input file and output files in:
AddRowsToTable.zip
The text was updated successfully, but these errors were encountered: