2

如何在保留单元格属性值(例如行高/宽度)的情况下复制/粘贴单元格范围。我执行以下操作:

$excel=new-object -comobject excel.application;
$excel.visible=$true;
$SourceWorkBook=$Excel.Workbooks.open("c:\ret.xls");
$TargetWorkBook=$excel.workBooks.open("c:\test.xlsx");
$SourceWorkBook.WorkSheets.item(1).activate();
$SourceRange=$SourceWorkBook.WorkSheets.item(1).range("A6","P17");
$SourceRange.copy() | out-null;
$TargetWorkBook.worksheets.item(1).paste();

结果一团糟。行/列的高度/宽度与其原始值不同。

4

1 回答 1

2

There is a Range.PasteSpecial which corresponds to what you can do with the keyboard/menus. It allows you to specify what you want copying, see: http://msdn.microsoft.com/en-us/library/office/ff839476 And http://msdn.microsoft.com/en-us/library/office/ff837425

I found some interesting examples (in PowerShell) here: http://theolddogscriptingblog.wordpress.com/2010/06/01/powershell-excel-cookbook-ver-2/

于 2012-08-26T08:19:25.493 回答