一、通用操作
1)用Excel Application Scope读写excel, 操作datatable;
2)手动新建dt(可固定表头),进行dt的增删筛选,然后写入excel;
二、.Net写法,用inokeCode来操作excel
1)文本打开xaml文件,
a. 在<sco:Collection x:TypeArguments="x:String">标签下级插入 <x:String>Microsoft.Office.Interop.Excel</x:String>
b. 在<sco:Collection x:TypeArguments="AssemblyReference">标签下级插入 <AssemblyReference>Microsoft.Office.Interop.Excel</AssemblyReference>
RPA之家(www.rpazj.com/)是中国具有影响力的R…
2)invoke里面进行.net代码操作
'Dim xlApp As Microsoft.Office.Interop.Excel.Application = Nothing Dim xlWorkBooks As Microsoft.Office.Interop.Excel.Workbooks=Nothing 'Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook=Nothing Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet=Nothing Dim xlWorkSheets As Microsoft.Office.Interop.Excel.Sheets=Nothing Dim rowcount As Integer Dim colcount As Integer
xlApp=New Microsoft.Office.Interop.Excel.ApplicationClass xlApp.DisplayAlerts=False //不提示一些超链接操作 xlWorkBooks=xlApp.Workbooks xlWorkBook=xlWorkBooks.Open(filePath) xlApp.Visible = True //打开不弹窗 xlWorkSheets=xlWorkBook.Sheets
'xlWorkBook.Save() 'xlApp.Quit() Dim xlApp As Microsoft.Office.Interop.Excel.Application = Nothing Dim xlWorkBooks As Microsoft.Office.Interop.Excel.Workbooks=Nothing Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook=Nothing Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet=Nothing Dim xlWorkSheets As Microsoft.Office.Interop.Excel.Sheets=Nothing
xlApp=New Microsoft.Office.Interop.Excel.ApplicationClass xlApp.DisplayAlerts=False xlWorkBooks=xlApp.Workbooks xlWorkBook=xlWorkBooks.Open(filePath) xlApp.Visible = False xlWorkSheets=xlWorkBook.Sheets
xlWorkSheet= CType(xlWorkSheets(1),Microsoft.Office.Interop.Excel.Worksheet)
#删除空行 Try Dim range As Microsoft.Office.Interop.Excel.Range = xlWorkSheet.Range("A1:A"&rows) Dim entireRow As Microsoft.Office.Interop.Excel.Range = range.EntireRow entireRow.Delete(Microsoft.Office.Interop.Excel.XlDirection.xlUp) xlWorkBook.Save() Catch ex As Exception Finally xlApp.Quit() End Try
———————————————— 版权声明:本文为CSDN博主「旺枝」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:blog.csdn.net/m0_37991778…