Dim Book As New XLS.Book(ProjectPath & "Attachments\监造周报.xls")
Dim fl As String = ProjectPath & "Reports\监造周报.xls"
Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表
'Sheet.Locked = True '禁止编辑
With Sheet.PrintSetting
'页眉左边为日期,中间为时间,右边为表名
.Header = "&L&D &C&T &R&F"
'在页脚右边打印页号和总页数
.Footer = "&R第&P页,总&N页"
End With
Book.Build() '生成细节区
Book.Save(fl) '保存工作簿
Dim App As New MSExcel.Application
try
App.DisplayAlerts = False '加上此行可禁止弹出合并前的提示
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(fl)
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim sr As Integer = 1
Dim prev As String = ws.Cells(1,1).Text
For r As Integer = 2 To Ws.UsedRange.Rows.count
If ws.Cells(r, 1).Text <> prev AndAlso ws.Cells(r, 1).Text <> Nothing Then
Dim Rg As MSExcel.Range = ws.Range("A" & sr & ":A" & r-1)
Rg.Merge
sr = r
prev = ws.Cells(r, 1).Text
End If
Next
App.Visible = True
catch ex As exception
msgbox(ex.message)
app.quit
End try