Office 365和Excel

Office 365和Excel,excel,windows,Excel,Windows,所以,这里是新手。我有一个在Visual studio中开发的程序。基本功能是从几个数据库中提取信息,并提供一个列表,从中选择选项,导出为Excel文件,并提供一个列表。它有一个带有相关格式和信息的“模板”Excel文件,最初复制该文件,然后写入该副本。它利用网络上的共享文件,并将此新文件保存到网络。以前,它运行得相当好,但现在,我们的办公室已经过渡到更新版本的Windows 10和7,在这一过程中,我们还学习了office 365,并且现在正在使用它。问题是,当程序现在抓取Excel文件时,它

所以,这里是新手。我有一个在Visual studio中开发的程序。基本功能是从几个数据库中提取信息,并提供一个列表,从中选择选项,导出为Excel文件,并提供一个列表。它有一个带有相关格式和信息的“模板”Excel文件,最初复制该文件,然后写入该副本。它利用网络上的共享文件,并将此新文件保存到网络。以前,它运行得相当好,但现在,我们的办公室已经过渡到更新版本的Windows 10和7,在这一过程中,我们还学习了office 365,并且现在正在使用它。问题是,当程序现在抓取Excel文件时,它不断抛出文件被锁定以进行编辑的错误,并且不允许它覆盖或访问该文件。更新后的Office 365是it工作中唯一的更改。我原本以为这是与操作系统相关的,但这发生在7和10个用户身上。我还让它在一台没有当前Office更新的计算机上运行,没有错误,一旦它一夜之间更新到当前的Office,它就坏了。Excel中的某些更改是否会导致与此冲突?我是否可以添加一行代码来绕过此问题?我尝试过readonly=False、notify=False、ignorereadyonlyrecommended=true,我尝试过添加thread.sleep(500),以防服务器上的锁文件更新之间出现延迟。也许我只是错过了一个显而易见的解决方案

更新:

Dim ExcelApp As New Excel.Application 'create new excel application
        ***Dim ExcelWkBk = ExcelApp.Workbooks.Open(filepath, [ReadOnly]:=False, Notify:=False) 'open the unitfile***
        Try
            Dim ExcelSheet As Excel.Worksheet = ExcelWkBk.Sheets("Distributor") 'open the distributor sheet
            ExcelApp.Visible = False 'make the application invisible
            ExcelApp.DisplayAlerts = False 'don't display any alerts, this operation is meant to silent to the user
            ExcelApp.ScreenUpdating = False 'this slows down the process so I turned off updates
            ExcelSheet.Range("A" & columnRow, "P" & aftAdjRow - 1).Name = "Unit" 'specifies the region which is the unit data
            ExcelSheet.Range("G" & titleRow + 1, "K" & aftAdjRow).Value2 = ExcelSheet.Range("G" & titleRow + 1, "K" & aftAdjRow).Value2 'refreshes the unit number values
            ExcelSheet.Range("G" & columnRow + 1, "G" & aftAdjRow).NumberFormat = "0"
            ExcelSheet.Range("I" & columnRow + 1, "K" & aftAdjRow).NumberFormat = "$#,##0;$-#,##0;$0;" 'custom format for the prices
            ExcelSheet.Rows(columnRow).EntireRow.Hidden = True 'hide column and config rows
            'ExcelSheet.Rows(configRow).EntireRow.Hidden = True
            'ExcelSheet.Rows(configRow + 1).EntireRow.Hidden = True
            ExcelSheet.Columns("E").EntireColumn.WrapText = True
            ExcelSheet.Range("I" & titleRow, "K" & titleRow).HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter 'center prices column
            ExcelSheet.Range("Unit").VerticalAlignment = Excel.XlVAlign.xlVAlignTop 'change alignment
            ExcelSheet.Range("A" & columnRow, "P" & distRowCnt + 8).Font.Name = "Courier New" 'change font
            ExcelSheet.Range("A" & columnRow, "P" & distRowCnt + 9).Font.Size = 10

Dim ExcelWkBk = ExcelApp.Workbooks.Open(filepath, [ReadOnly]:=False, Notify:=False) 'open the unitfile - Is where it flags the error

System.Runtime.InteropServices.COMException: ''testing1.xls' cannot be accessed. The file may be corrupted, located on a server that is not responding, or read-only.'

如果我试图保存一个新文件、覆盖一个现有文件或打开一个现有文件,即使没有理由将其锁定或打开,其行为也会像文件被锁定以进行编辑或只读一样。

您是否可以共享其余代码,或逐行检查以查看错误所在?Dim ExcelWkBk=ExcelApp.WORKS.open(filepath,[ReadOnly]:=False,Notify:=False)是它在哪里中断的标志此代码在哪里运行,它是如何触发的?您能否将这些详细信息也添加到原始问题中?