Specifying cells in excel using TCOM

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

Answers


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

Need Your Help

Timed events with php/MySQL

php sql mysql events timing

I need a way to modify a value in a table after a certain amount of time has passed. My current method is as follow:

Sort Multidimensional Array by Column

php arrays sorting multidimensional-array

I have a multi-dimensional array and have tried every example code I can find from this website to sort it by a column. Not a single snippet I have tried has worked and for some reason all of them ...