Uipath操作Excel

一、通用操作

1)用Excel Application Scope读写excel, 操作datatable;

2)手动新建dt(可固定表头),进行dt的增删筛选,然后写入excel;

 

二、.Net写法,用inokeCode来操作excel

1)文本打开xaml文件,

    a. 在标签下级插入 Microsoft.Office.Interop.Excel

    b. 在标签下级插入                                                                    Microsoft.Office.Interop.Excel

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

 

你可能感兴趣的:(UiPath)