如何用C#在不循环的情况下将矩阵复制到Ms Word表中



我确实将整个字符串[4723.11]复制到Word中,但每次循环和插入每个单元格都需要花费大量时间。我想做的是将整个字符串[4723.11]直接复制到MS Word中。如果还有一种方法可以将Excel工作表的内容复制到MS Word,我将不胜感激,因为它可以以任何方式解决问题。

public void WriteContent(string[,] array, Word.Table oDoc)
{
// This is where I fill the Excel worksheet with the string [4273,11] array
Range range = (Range)m_worksheet.Cells[1, 1];
range = range.get_Resize(4273, 11);
// Assign the 2-d array to the Excel Range
range.set_Value(Microsoft.Office.Interop.Excel.XlRangeValueDataType.xlRangeValueDefault, array);
//This is Where I want to Paste the Excel "range" into the word document
}

您可以在办公应用程序之间进行复制和粘贴,但这是一个非常大的复制范围,因此需要一些延迟或检查。此回复来自Office知识,而非c#。

range.Copy();
_wordApp.Selection.Paste();

比你。我已经做了,问题是如何选择特定的范围,所以我做了这个

m_Worksheet.get_Range("A1", "K5000").Copy();

This range = range.get_Resize(4273, 11);

下一行表示您的范围已经选定。

最新更新