Forum Discussion
Have you checked out the how-to guide yet?
- abrar2210 years agoFrequent Contributor
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
- ghuff210 years agoContributor
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 NextSpecifically 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();