C# 粘贴特殊功能不复制日期-VSTO

C# 粘贴特殊功能不复制日期-VSTO,c#,excel,vsto,C#,Excel,Vsto,我正在使用VSTO加载项,尝试将一张图纸的值复制到另一张图纸,但仅粘贴为文本。在excel中,我可以手动打开一张新的工作表,将单元格设置为文本格式,然后将数据复制到上面。我正试图通过编程来实现这一点。下面是一些代码: Worksheet currentSheet; // This is the sheet I'm copying from Excel.Range currentRange = currentSheet.Cells.Application.Selection.Spe

我正在使用VSTO加载项,尝试将一张图纸的值复制到另一张图纸,但仅粘贴为文本。在excel中,我可以手动打开一张新的工作表,将单元格设置为文本格式,然后将数据复制到上面。我正试图通过编程来实现这一点。下面是一些代码:

    Worksheet currentSheet; // This is the sheet I'm copying from
    Excel.Range currentRange = currentSheet.Cells.Application.Selection.SpecialCells(
                                 Excel.XlCellType.xlCellTypeVisible,
                                 Type.Missing);

    Excel.Worksheet newWorksheet; // This is the sheet I'm copyng to
    newWorksheet.Cells.NumberFormat = "@"; // set the format of cells to text

    currentRange.Copy(); // Copy the data
    newWorksheet.Range["A1"].PasteSpecial(XlPasteType.xlPasteValues,
    XlPasteSpecialOperation.xlPasteSpecialOperationNone,
    System.Type.Missing,
    System.Type.Missing);
这是可行的,但是,有时我复制的数据将包含日期(例如2019-10-01),当我将其复制到新工作表时,它将以数字结束,即使我使用的是
XlPasteType.xlPasteValues
我只想将文本值带入新单元格。这可能吗?
谢谢

这里的一个快速测试显示
PasteSpecial(XlPasteType.xlPasteValuesAndNumberFormats)
保留单元格的文本格式

或者,在粘贴后应用格式:


FWIW我没有看到日期格式被明确地转换成数字格式。我看到单元格格式已应用于目标单元格。在我的例子中,它是“常规的”。

这里的一个快速测试显示
PasteSpecial(XlPasteType.xlPasteValuesAndNumberFormats)
保留单元格的文本格式

或者,在粘贴后应用格式:

FWIW我没有看到日期格式被明确地转换成数字格式。我看到单元格格式已应用于目标单元格。就我而言,这是“一般的”。

谢谢。“XlPasteType.xlPasteValuesAndNumberFormats”非常有用。谢谢。“XlPasteType.xlPasteValuesAndNumberFormats”起到了很好的效果。
newWorksheet.Range["A1"].PasteSpecial(XlPasteType.xlPasteValues,
  XlPasteSpecialOperation.xlPasteSpecialOperationNone,
  System.Type.Missing,
  System.Type.Missing);
newWorksheet.Cells.NumberFormat = "@";