'Excel
Dim app As Microsoft.Office.Interop.Excel.Application = Nothing
Dim workbook As Microsoft.Office.Interop.Excel.Workbook = Nothing
Dim sheet As Microsoft.Office.Interop.Excel.Worksheet = Nothing
Dim tlsheet As Microsoft.Office.Interop.Excel.Worksheet = Nothing
'路径
Dim ssDirectoryPath As String = ""
ssDirectoryPath = BB.MJ.openBrawserDialog(filepath)
If ssDirectoryPath Is Nothing _
OrElse ssDirectoryPath.Length = 0 Then
Return False
End If
'ExcelApplication
app = New Microsoft.Office.Interop.Excel.Application()
app.Visible = False
app.DisplayAlerts = False
'模板使用
workbook = app.Workbooks._Open(v_datadir.ToString() & "\" & c_tplpath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)
'模板シート
tlsheet = CType(workbook.Worksheets(1), Microsoft.Office.Interop.Excel.Worksheet)
sheet = tlsheet
If Not ssDirectoryPath.Last.ToString.Equals("\") Then
ssDirectoryPath = ssDirectoryPath & "\"
End If
Dim filename As String = ssDirectoryPath & "file"
'文件存在
If System.IO.File.Exists(filename) = True Then
If MsgBox("文件已经存在是否覆盖", MsgBoxStyle.OkCancel) = MsgBoxResult.Cancel Then
Return False
End If
End If
'复制sheet
tlsheet.Copy(Type.Missing, sheet)
'Excel内容部分自定义
'sheet.Cells(rIdx, cIdx)="文本内容"
'删除模板sheet
tlsheet.Delete()
'另存为模式
workbook.Saved = True
workbook.SaveAs(filename, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)
'关闭Excel
workbook.Close(False, DBNull.Value, DBNull.Value)
workbook = Nothing
'回收Excel内存
app.Quit()
app = Nothing