1

我确实将整个字符串 [4273,11] 复制到 Word 中,但是每次循环和插入每个单元格都需要很长时间。我想要做的是将整个字符串 [4273,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
}
4

2 回答 2

1

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

range.Copy();
_wordApp.Selection.Paste();
于 2012-08-29T11:33:41.810 回答
0

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

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

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

下一行表示您的范围已被选中。

于 2012-09-29T15:49:59.360 回答