A
anon1m0us
I get a file name in the directory and modify the cells with making
bold etc.
when excel.visible=TRUE it works. However, when excel.visible=FALSE
nothing happens.
Why?
newdir=Dir.getwd
x=1
excel = WIN32OLE::new("excel.application")
excel.visible=FALSE
Dir["*.xls"].each { |file|
book = excel.Workbooks.Open("#{newdir}\\#{file}")
sheetname=File.basename("#{file.upcase}",".XLS")
excel.Worksheets("#{sheetname}").Name="Sheet1"
excel.Worksheets("Sheet1").Range("A:A").NumberFormat = ("yyyy-mm-dd
hh:mm:ss")
excel.Worksheets("Sheet1").Range("a1:g1").Font.Bold = 1
excel.Worksheets("Sheet1").Range("a1:g1").Interior.ColorIndex = 6
excel.Worksheets("Sheet1").Columns.AutoFit
excel.Worksheets("Sheet1").Select
excel.Worksheets("Sheet1").Rows("2:2").Select
excel.ActiveWindow.FreezePanes =1
excel.DisplayAlerts = 0
book.SaveAs("#{file}")
excel.DisplayAlerts = 1
book.close true
}
excel.quit()
bold etc.
when excel.visible=TRUE it works. However, when excel.visible=FALSE
nothing happens.
Why?
newdir=Dir.getwd
x=1
excel = WIN32OLE::new("excel.application")
excel.visible=FALSE
Dir["*.xls"].each { |file|
book = excel.Workbooks.Open("#{newdir}\\#{file}")
sheetname=File.basename("#{file.upcase}",".XLS")
excel.Worksheets("#{sheetname}").Name="Sheet1"
excel.Worksheets("Sheet1").Range("A:A").NumberFormat = ("yyyy-mm-dd
hh:mm:ss")
excel.Worksheets("Sheet1").Range("a1:g1").Font.Bold = 1
excel.Worksheets("Sheet1").Range("a1:g1").Interior.ColorIndex = 6
excel.Worksheets("Sheet1").Columns.AutoFit
excel.Worksheets("Sheet1").Select
excel.Worksheets("Sheet1").Rows("2:2").Select
excel.ActiveWindow.FreezePanes =1
excel.DisplayAlerts = 0
book.SaveAs("#{file}")
excel.DisplayAlerts = 1
book.close true
}
excel.quit()