The library I use is microsoft.excel
I cannot use the first page of excel, I only work with the second page.How can I set the number of pages.
this is my code.
excelFile.SaveAs(path);
Excel.Application application = new Excel.Application();
Excel.Workbook workbook = application.Workbooks.Open(path);
Excel.Worksheet worksheet = workbook.ActiveSheet;
Excel.Range range = worksheet.UsedRange;
for (int i = 3; i <= range.Rows.Count; i++)
{
Google lm = new Google();
lm.Default_channel_grouping = ((Excel.Range)range.Cells[i, 1]).Text;
lm.MonthOfYear = ((Excel.Range)range.Cells[i, 2]).Text;
lm.Date = ((Excel.Range)range.Cells[i, 3]).Text;
lm.Segment = ((Excel.Range)range.Cells[i, 4]).Text;
lm.Users = ((Excel.Range)range.Cells[i, 5]).Text;
lm.NewUsers = ((Excel.Range)range.Cells[i, 6]).Text;
lm.Ecommerce = ((Excel.Range)range.Cells[i, 7]).Text;
lm.Transactions = ((Excel.Range)range.Cells[i, 7]).Text;
lm.Revenue = ((Excel.Range)range.Cells[i, 7]).Text;
sdb.Google.Add(lm);
sdb.SaveChanges();
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You can get the number of sheets (I assume that’s what you mean by pages) by accessing the Sheets property of the workbook:
Excel.Application application = new Excel.Application(); Excel.Workbook workbook = application.Workbooks.Open(path); var sheets = workbook.Sheets.Count;
To work with any sheet in the collection (in your case i = 2)
workbook.Sheets[i]
To add a sheet and make it active, use Sheets.Add
To select a worksheet as active:
((Excel.Worksheet)workbook.Sheets[1]).Select();
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0