AutoHotKey 写入现有 excel 文件,并删除保存提示
AutoHotKey Writing into a existing excel file, and remove save prompt
不,我正在尝试让我的测试代码填充我从网上抓取到 excel 文件中的信息。但是我似乎在某些数据中遇到了非法字符错误。当我尝试添加一些随机数据以将其保存到 excel 文件中时,它会提示我保存它。删除或过滤掉这些非法字符的最佳方法是什么?如果我必须使用 StrReplace 那很好,但我想知道这是否是最好的方法。以及如何将变量传递到 excel 文件中,即使没有错误我似乎在将 %variables% 传递到单元格中时遇到问题还有另一种方法吗?
下面是代码:
CloseExcel(){
oExcel := ComObjCreate("Excel.Application")
oExcel.DisplayAlerts := False ; This removes the prompt
FilePath := "C:\Users\GGVERA\Documents\aviability\test.csv" ; example path this works
cWorkbook := ComObjGet(FilePath) ; access Workbook object
oWorkbook.Sheets(1).Range("G2").Value := "TestData"
cWorkbook.Sheets(1).Range("H2").Value := %Name% ; Name
oWorkbook.Save()
oWorkbook.Close()
}
这会修改 Excel 中的 CSV 文件而不提示 "Do you want to save the changes you made to 'myfile.csv'?"
CloseExcel(FilePath){
oExcel := ComObjCreate("Excel.Application")
oExcel.DisplayAlerts := False
oWorkbook := ComObjGet(FilePath)
oWorkbook.Sheets(1).Range("G2").Value := "TestData"
oWorkbook.Save()
oWorkbook.Close()
}
我建议使用 RegExMatch() and RegExReplace() 从您抓取的网页中提取和清理信息。
不,我正在尝试让我的测试代码填充我从网上抓取到 excel 文件中的信息。但是我似乎在某些数据中遇到了非法字符错误。当我尝试添加一些随机数据以将其保存到 excel 文件中时,它会提示我保存它。删除或过滤掉这些非法字符的最佳方法是什么?如果我必须使用 StrReplace 那很好,但我想知道这是否是最好的方法。以及如何将变量传递到 excel 文件中,即使没有错误我似乎在将 %variables% 传递到单元格中时遇到问题还有另一种方法吗?
下面是代码:
CloseExcel(){
oExcel := ComObjCreate("Excel.Application")
oExcel.DisplayAlerts := False ; This removes the prompt
FilePath := "C:\Users\GGVERA\Documents\aviability\test.csv" ; example path this works
cWorkbook := ComObjGet(FilePath) ; access Workbook object
oWorkbook.Sheets(1).Range("G2").Value := "TestData"
cWorkbook.Sheets(1).Range("H2").Value := %Name% ; Name
oWorkbook.Save()
oWorkbook.Close()
}
这会修改 Excel 中的 CSV 文件而不提示 "Do you want to save the changes you made to 'myfile.csv'?"
CloseExcel(FilePath){
oExcel := ComObjCreate("Excel.Application")
oExcel.DisplayAlerts := False
oWorkbook := ComObjGet(FilePath)
oWorkbook.Sheets(1).Range("G2").Value := "TestData"
oWorkbook.Save()
oWorkbook.Close()
}
我建议使用 RegExMatch() and RegExReplace() 从您抓取的网页中提取和清理信息。