TonyM
11 years agoOccasional Contributor
Cannot write to Excel properly.
Hello,
My function for writing to excel is not working properly. It will write some data in the beginning of the file, but doesn't seem to write anything beyond row 20 or column N.
Sometimes it also has problems writing to *.xlsx .
Please help!!
Write to Excel
function writeToXL(fileName, sheetName, row, col, data)
{
try{
var app = Sys.OleObject("Excel.Application");
var book = app.Workbooks.Open(fileName);
var sheet = book.Sheets(sheetName);
app.DisplayAlerts = false;
sheet.Cells(row, col) = aqConvert.VarToStr(data);
Log.Message("Following data was added to " +row +"," +col + " cell : "+ data)
book.Save();
book.Close();
app.Quit();
}catch(e){
Log.Message(e.description);
}
}
My function for writing to excel is not working properly. It will write some data in the beginning of the file, but doesn't seem to write anything beyond row 20 or column N.
Sometimes it also has problems writing to *.xlsx .
Please help!!
Write to Excel
function writeToXL(fileName, sheetName, row, col, data)
{
try{
var app = Sys.OleObject("Excel.Application");
var book = app.Workbooks.Open(fileName);
var sheet = book.Sheets(sheetName);
app.DisplayAlerts = false;
sheet.Cells(row, col) = aqConvert.VarToStr(data);
Log.Message("Following data was added to " +row +"," +col + " cell : "+ data)
book.Save();
book.Close();
app.Quit();
}catch(e){
Log.Message(e.description);
}
}
- Hi M R, I tried the following calls to your function for an empty xlsx document multiple times and they worked fine every time:
var fileName = "C:\\Temp\\testwrite.xlsx";
writeToXL( fileName, "Sheet1", 2, 2, "test" );
writeToXL( fileName, "Sheet1", 30, 30, "test" );
writeToXL( fileName, "Sheet1", 30, "n", "test" );
writeToXL( fileName, "Sheet1", 30, "AA", "test" );
Could there perhaps be something configured in the document you are trying to write to that might prevent this from working?
Regards,
Phil Baird