问题描述
我正在尝试自动化复制和粘贴数据的过程,但是对我来说,保持格式的格式是一样的。
I am trying to automate the process of copying and pasting data but it is important for me to keep the formatting of the cells the same.
我尝试使用 PasteSpecial(-4163)
,但没有起作用。奇怪的是,它转换了一些值粗体和其他值它不加粗(?)。
I have tried using PasteSpecial(-4163)
but that has not worked. Strangely enough it turned some values Bold and other values it un-bold (?).
这是我创建的执行复制和粘贴的功能。
任何人都有任何建议?
Here is the function I created to carry out the copying and pasting.Anybody have any suggestions?
function CopyPasteRange
{
#args[0] = sheet
#args[1] = row
#args[2] = column
$range = $args[0].Cells.Item($args[1], ($args[2])).EntireColumn;
$range.Copy();
$args[0].Cells.Item(1, $args[2]).PasteSpecial(-4163);
}
推荐答案
根据的您正在粘贴值(例如 xlPasteValues
)。您将不得不使用类似 13 ( xlPasteAllUsingSourceTheme
)的XlPasteType参数运行第二次PasteSpecial操作。
According to the Range.PasteSpecial method's XlPasteType enumeration you are currently pasting values (e.g. xlPasteValues
). You will have to run a second PasteSpecial operation using something like 13 (xlPasteAllUsingSourceTheme
) as the XlPasteType parameter.
function CopyPasteRange
{
#args[0] = sheet
#args[1] = row
#args[2] = column
$range = $args[0].Cells.Item($args[1], ($args[2])).EntireColumn;
$range.Copy();
$args[0].Cells.Item(1, $args[2]).PasteSpecial(-4163);
$args[0].Cells.Item(1, $args[2]).PasteSpecial(13);
}
这篇关于复制粘贴Powershell Excel保持格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!