Forum Discussion
Yes I have seen.
But in this code I cant see where i can pass which value i want to export to excel.
Thanks
A
This is the section of code where they are writing a value to Excel:
' Write an index of the current row and column to a cell
rowCount = sheet.UsedRange.Rows.Count + 1
For row = rowCount To rowCount + maxrow - 1
For col = 1 To maxcol
sheet.Cells(row, col) = row & ", " & col
Next
Next
Specifically in the line fifth line where they call: sheet.Cells(row, col) = whatever value you want to be written to excel
Obviously you don't have to use for loops like they did. Just call sheet.Cells() with whatever row and column number you desire and set it equal to whatever value you want (course it has to be a value type that can be written in Excel)
- abrar2210 years agoFrequent Contributor
Thanks.
I got somewhere but when I am writing to 1 col and row its copying to 5 cols and rows( see attached) :
{
var maxcol = 1, maxrow = 1;
var app = Sys.OleObject("Excel.Application");
var book = app.Workbooks.Open(fname);
var sheet = book.Sheets(sheetName);
app.DisplayAlerts = false;
// Write an index of the current row and column to a cell
var rowCount = sheet.UsedRange.Rows.Count + 1;
for(var row = rowCount; row < rowCount + maxrow; row++)
for(var col = 1; col <= maxcol; col++)
sheet.Cells(row, col) = ProductID;
book.Save();
app.Quit();- ghuff210 years agoContributor
Then get rid of the for loops and just set the row/col value to whatever row and column you want it to write to.
- abrar2210 years agoFrequent Contributor
Yes, But if ran the test suit it will always write to 1,1. Example if i have 10 tests running it should copy the Product ID intrementally in excel rows. Is there any way to do it?
Thanks