Excel 2010-';在文件中找不到关系ID为rId1的图像部分。';将工作簿的工作表复制到其他工作簿时

Excel 2010-';在文件中找不到关系ID为rId1的图像部分。';将工作簿的工作表复制到其他工作簿时,excel,xlsm,Excel,Xlsm,我有一个源excel工作簿(XLSM格式),其中有包含图像的工作表。这些工作表通过VB.NET后期绑定以编程方式复制到另一个(目标)工作簿(XLSM)中。完成所有复制后,我保存工作簿并启动它。在打开的excel工作簿中,我在放置图像的所有位置都看到错误消息“文件中未找到关系ID为rId1的图像部分”。 所有操作都在客户端计算机中完成,没有可用的服务器端代码 Dim SourceExcelWorkbook As Excel.Workbook = Nothing Dim TargetExc

我有一个源excel工作簿(XLSM格式),其中有包含图像的工作表。这些工作表通过VB.NET后期绑定以编程方式复制到另一个(目标)工作簿(XLSM)中。完成所有复制后,我保存工作簿并启动它。在打开的excel工作簿中,我在放置图像的所有位置都看到错误消息“文件中未找到关系ID为rId1的图像部分”。 所有操作都在客户端计算机中完成,没有可用的服务器端代码

 Dim SourceExcelWorkbook As Excel.Workbook = Nothing
    Dim TargetExcelWorkbook As Excel.Workbook = Nothing
    Dim TargetExcelSheets As Excel.Sheets = Nothing
    Dim SourceExcelSheets As Excel.Sheets = Nothing
    Dim CopyWorkSheet As Excel.Worksheet = Nothing

    Dim XLApp As New Excel.Application
    XLApp.Visible = False
    XLApp.DisplayAlerts = False
    XLApp.ScreenUpdating = False

    Dim pobjExcelWorkbooks As Excel.Workbooks = XLApp.Workbooks

    SourceExcelWorkbook = pobjExcelWorkbooks.Open("source file path")
    TargetExcelWorkbook = pobjExcelWorkbooks.Open("target file path")

    TargetExcelSheets = TargetExcelWorkbook.Worksheets
    SourceExcelSheets = SourceExcelWorkbook.Worksheets

    Dim OriginalSheetCount As Integer = TargetExcelSheets.Count
    Dim SheetCount As Integer = OriginalSheetCount
    Dim SheetsToBeCopiedCount As Integer = SourceExcelSheets.Count

    While SheetsToBeCopiedCount > 0
        Dim lobjAfterSheet As Object = TargetExcelSheets.Item(SheetCount)
        CopyWorkSheet = SourceExcelSheets.Item(1)
        CopyWorkSheet.Move(After:=lobjAfterSheet)
        SheetCount = SheetCount + 1
        TargetExcelWorkbook.Save()
        SheetsToBeCopiedCount = SheetsToBeCopiedCount - 1
    End While

    TargetExcelWorkbook.Save()
有趣的是,这个问题在Excel 2013中没有出现,它正确地显示了图像。只有在2010年和2007年才观察到这个问题。这是Excel 2010和2007中的已知错误吗?如果是,任何人都可以向我提供到罚单的官方链接,以便我可以跟踪问题并在可用时获得热修复

 Dim SourceExcelWorkbook As Excel.Workbook = Nothing
    Dim TargetExcelWorkbook As Excel.Workbook = Nothing
    Dim TargetExcelSheets As Excel.Sheets = Nothing
    Dim SourceExcelSheets As Excel.Sheets = Nothing
    Dim CopyWorkSheet As Excel.Worksheet = Nothing

    Dim XLApp As New Excel.Application
    XLApp.Visible = False
    XLApp.DisplayAlerts = False
    XLApp.ScreenUpdating = False

    Dim pobjExcelWorkbooks As Excel.Workbooks = XLApp.Workbooks

    SourceExcelWorkbook = pobjExcelWorkbooks.Open("source file path")
    TargetExcelWorkbook = pobjExcelWorkbooks.Open("target file path")

    TargetExcelSheets = TargetExcelWorkbook.Worksheets
    SourceExcelSheets = SourceExcelWorkbook.Worksheets

    Dim OriginalSheetCount As Integer = TargetExcelSheets.Count
    Dim SheetCount As Integer = OriginalSheetCount
    Dim SheetsToBeCopiedCount As Integer = SourceExcelSheets.Count

    While SheetsToBeCopiedCount > 0
        Dim lobjAfterSheet As Object = TargetExcelSheets.Item(SheetCount)
        CopyWorkSheet = SourceExcelSheets.Item(1)
        CopyWorkSheet.Move(After:=lobjAfterSheet)
        SheetCount = SheetCount + 1
        TargetExcelWorkbook.Save()
        SheetsToBeCopiedCount = SheetsToBeCopiedCount - 1
    End While

    TargetExcelWorkbook.Save()

这似乎更像是一个谷歌任务,而不是一个编程问题也许您可以向我们展示您的代码或您迄今为止尝试过的内容。@Tom我包括了示例代码。源excel工作簿包含这些图像。执行上述代码并打开目标工作簿后,我会看到图像错误。有什么建议吗?不幸的是,我没有一个旧的excel版本来测试这个,但我的第一个猜测是
.move
。也许excel只是创建了一个对现有工作簿/工作表的引用,而不是复制图片。@Tom“移动”功能有什么改进吗?我无法使用“复制”,因为我在源工作簿中有指向其他工作簿的链接,如果我将它们复制到目标工作簿中,这些链接可能会断开。您是否使用了
.Copy
,或者这只是一个假设?就我所读到的,这应该是正确的选择。