从Unmerging excel rows, and duplicate data c#获取部分代码
我正在将Excel工作表转换为CSV。有些单元格被合并了,所以我想取消合并并复制这些数据,而不是丢失它。
$Script:comExcelWB = $Script:comExcelApp.Workbooks.Open($TargetXlsxPath.FullName)
foreach ($Script:comExcelWS in $Script:comExcelWB.Worksheets) {
if ($Script:comExcelWS.Visible) {
$Script:comExcelWS.Select()
foreach ($Script:comExcelRNG in $Script:comExcelWS.UsedRange) {
if ($Script:comExcelRNG.MergeCells) {
$Script:comExcelMA = $Script:comExcelRNG.MergeArea
$Script:comExcelRNG.UnMerge()
$Script:comExcelMA.Value = $Script:comExcelRNG.Value # Throws 0x800A03EC here
}
}
$Script:comExcelWB.SaveAs("$($WSDestination.FullName)\$($Script:comExcelWS.Name).csv",
[Microsoft.Office.Interop.Excel.XlFileFormat]::xlCSV, [Microsoft.Office.Interop.Excel.XlSaveAsAccessMode]::xlNoChange)
}
}
我错过了什么?
1条答案
按热度按时间izkcnapc1#
或许,这一切都与空值有关吧?
NULL
,检查范围,如果不是,继续设置Value2
并转换为String
(以避免Double
->String
转换错误)