楼主,你用下面这段代码吧。
需要你在excel模板里填入公式,但注意公式要左移一位(比如 E4:E9 要写成 D4:D9)
原本想帮你自动左移一位的,不过这样会复杂一些。你试一下,测试有效。
Dim Book_Mod As New XLS.Book(ProjectPath & "Attachments\2012 NCB Budget Actuals.xls") Dim Book_Rep As New XLS.Book(ProjectPath & "Attachments\2012 NCB Budget Actuals.xls") Dim fl As String = ProjectPath & "Reports\2012 NCB Budget Actuals.xls"
Book_Rep.Build() '生成细节区
For Each sheet As XLS.Sheet In book_Mod.Sheets For i As Integer = 0 To sheet.Rows.Count - 1 For j As Integer = 0 To sheet.Cols.Count - 1 If sheet(i, j).Formula <> "" Then '是公式 book_Rep.Sheets(sheet.Name)(i, j-1).Formula = sheet(i, j).Formula '把公式重新写入 End If Next Next Next
Book_Rep.Save(fl) Dim Proc As New Process Proc.File =fl Proc.Start()
|