Reputation: 573
The command $cells Item 2 A {SomeText} doesn't set the text in the cell A2 instead it assigns the text in the cell A1. Any idea on why its behaving like this???
set application [::tcom::ref createobject "Excel.Application"]
set XlFileFormat(xlCSV) [expr 6]
set workbooks [$application Workbooks]
set workbook [$workbooks Add]
$application DisplayAlerts False
set worksheets [$workbook Worksheets]
set worksheet [$worksheets Item [expr 1]]
set cells [$worksheet Cells]
$cells Item 2 A {Range}
$workbook SaveAs {c:\test.csv} $XlFileFormat(xlCSV)
$application Quit
Upvotes: 0
Views: 983
Reputation: 55533
Okay, here's an explanation: when saving to CSV, Excel seems to save just the data which form the "bounding box" inside the (virtualized) sheet grid. In other words, you have not modified any data in the cells of the first row, and hence it's not saved.
This simple program (JScript for WSH):
var app = new ActiveXObject("Excel.Application");
var wbs = app.Workbooks;
var wb = wbs.Add;
var wss = wb.Worksheets;
var ws = wss.Item(1);
var cells = ws.Cells;
app.DisplayAlerts = false;
cells.Item(2, "B") = "B2";
cells.Item(2, "C") = "C2";
cells.Item(3, "B") = "B3";
cells.Item(3, "C") = "C3";
wb.SaveAs("foo.csv", 6);
app.Quit();
which sets four cells arranged in a rectangular block offset by one column and one row from the top-left corner of the sheet, produces this CSV file:
B2,C2
B3,C3
Upvotes: 1