I have the following:
private void ProcessSpreadsheet(string filename)
{
Microsoft.Office.Interop.E
xcel.Appli
cation xlApp;
// Excel application object
Microsoft.Office.Interop.E
xcel.Workb
ook xlWorkBook;
// Excel Workbook object
Microsoft.Office.Interop.E
xcel.Works
heet xlWorkSheet;
// Excel Worksheet object
Microsoft.Office.Interop.E
xcel.Range
inputRange;
// Excel Worksheet Range object
int rowCount;
int currRow;
// row iterator
string gradeName;
// character input variables
double Price;
// price as a decimal number
Microsoft.Office.Interop.E
xcel.Range
cellvalue;
double[,] discounts = new double[5, 4];
int pricesColumn;
// Define the input SS and open the 1st worksheet
xlApp = new Microsoft.Office.Interop.E
xcel.Appli
cation();
xlWorkBook = xlApp.Workbooks.Open(filen
ame);
xlWorkSheet = (Microsoft.Office.Interop.
Excel.Work
sheet)xlWo
rkBook.Wor
ksheets.It
em(1);
// Store the rows and columns used in the input SS into inputRange
inputRange = xlWorkSheet.UsedRange;
// Read all used rows in the input SS, starting at the 11th row (rows are numbered from 0)
// Data of interest is in columns O and R (numbered 15 and 18 respectively)
for (rowCount = 10; rowCount <= inputRange.Rows.Count; rowCount++)
{
// Read the grade name and price
// skip rows where the grade name is empty
try
{
// Initial prices load file has the prices in column 16
// All other load files have their prices in column 18
if (initialButton.Checked == true)
{
pricesColumn = 16;
}
else
{
pricesColumn = 18;
}
cellvalue = (Microsoft.Office.Interop.
Excel.Rang
e)inputRan
ge.Cells(r
owCount, pricesColumn);
if (Strings.Len(cellvalue.Val
ue) > 0)
{
if (cellvalue.Value.ToString == "Stones" | cellvalue.Value.ToString == "Tough")
{
// all prices have been read
currRow = rowCount + 1;
// skip a row to where the discounts are
break; // TODO: might not be correct. Was : Exit For
}
Price = (double)cellvalue.Value;
cellvalue = (Microsoft.Office.Interop.
Excel.Rang
e)inputRan
ge.Cells(r
owCount, 15);
gradeName = cellvalue.Value.ToString;
Insert_Price_List_Detail(g
radeName, Price);
// insert the prices
}
}
catch
{
Console.WriteLine("Excepti
on has occurred.");
}
}
// Process discounts
for (rowCount = currRow; rowCount <= currRow + 3; rowCount++)
{
// Read the discounts
try
{
cellvalue = (Microsoft.Office.Interop.
Excel.Rang
e)inputRan
ge.Cells(r
owCount, 16);
if (Strings.Len(cellvalue.Val
ue) > 0)
{
discounts[rowCount - currRow, 0] = (double)cellvalue.Value;
cellvalue = (Microsoft.Office.Interop.
Excel.Rang
e)inputRan
ge.Cells(r
owCount, 17);
discounts[rowCount - currRow, 1] = (double)cellvalue.Value;
cellvalue = (Microsoft.Office.Interop.
Excel.Rang
e)inputRan
ge.Cells(r
owCount, 18);
if (cellvalue.Value.ToString != "N/A")
{
// Des Barley is the last discount
discounts[rowCount - currRow, 2] = (double)cellvalue.Value;
Update_Price_List_Header_w
ith_Discou
nts(discou
nts);
// save the discounts
break; // TODO: might not be correct. Was : Exit For
}
else
{
discounts[rowCount - currRow, 2] = 0;
}
}
}
catch
{
Console.WriteLine("Excepti
on has occurred.");
}
}
inputRange = null;
xlWorkSheet = null;
if (xlWorkBook != null)
{
xlWorkBook.Close(false);
}
xlWorkBook = null;
if (xlApp != null)
{
xlApp.Quit();
}
xlApp = null;
}
Error 1 Cannot apply indexing with [] to an expression of type 'method group' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 37 26 InitialPriceReportingSprea
dsheet
Error 2 Property, indexer, or event 'Item' is not supported by the language; try directly calling accessor method 'Microsoft.Office.Interop.
Excel.Shee
ts.get_Ite
m(object)'
C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 38 91 InitialPriceReportingSprea
dsheet
Error 3 The name 'initialButton' does not exist in the current context C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 54 25 InitialPriceReportingSprea
dsheet
Error 4 'Microsoft.Office.Interop.
Excel.Rang
e.Cells' is a 'property' but is used like a 'method' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 62 82 InitialPriceReportingSprea
dsheet
Error 5 The name 'Strings' does not exist in the current context C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 63 25 InitialPriceReportingSprea
dsheet
Error 6 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Excel.Rang
e.get_Valu
e(object)'
or 'Microsoft.Office.Interop.
Excel.Rang
e.set_Valu
e(object, object)' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 63 47 InitialPriceReportingSprea
dsheet
Error 7 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Excel.Rang
e.get_Valu
e(object)'
or 'Microsoft.Office.Interop.
Excel.Rang
e.set_Valu
e(object, object)' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 65 39 InitialPriceReportingSprea
dsheet
Error 8 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Excel.Rang
e.get_Valu
e(object)'
or 'Microsoft.Office.Interop.
Excel.Rang
e.set_Valu
e(object, object)' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 65 78 InitialPriceReportingSprea
dsheet
Error 9 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Excel.Rang
e.get_Valu
e(object)'
or 'Microsoft.Office.Interop.
Excel.Rang
e.set_Valu
e(object, object)' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 72 51 InitialPriceReportingSprea
dsheet
Error 10 'Microsoft.Office.Interop.
Excel.Rang
e.Cells' is a 'property' but is used like a 'method' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 73 86 InitialPriceReportingSprea
dsheet
Error 11 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Excel.Rang
e.get_Valu
e(object)'
or 'Microsoft.Office.Interop.
Excel.Rang
e.set_Valu
e(object, object)' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 74 47 InitialPriceReportingSprea
dsheet
Error 12 'Microsoft.Office.Interop.
Excel.Rang
e.Cells' is a 'property' but is used like a 'method' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 91 82 InitialPriceReportingSprea
dsheet
Error 13 The name 'Strings' does not exist in the current context C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 92 25 InitialPriceReportingSprea
dsheet
Error 14 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Excel.Rang
e.get_Valu
e(object)'
or 'Microsoft.Office.Interop.
Excel.Rang
e.set_Valu
e(object, object)' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 92 47 InitialPriceReportingSprea
dsheet
Error 15 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Excel.Rang
e.get_Valu
e(object)'
or 'Microsoft.Office.Interop.
Excel.Rang
e.set_Valu
e(object, object)' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 94 78 InitialPriceReportingSprea
dsheet
Error 16 'Microsoft.Office.Interop.
Excel.Rang
e.Cells' is a 'property' but is used like a 'method' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 95 86 InitialPriceReportingSprea
dsheet
Error 17 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Excel.Rang
e.get_Valu
e(object)'
or 'Microsoft.Office.Interop.
Excel.Rang
e.set_Valu
e(object, object)' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 96 78 InitialPriceReportingSprea
dsheet
Error 18 'Microsoft.Office.Interop.
Excel.Rang
e.Cells' is a 'property' but is used like a 'method' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 97 86 InitialPriceReportingSprea
dsheet
Error 19 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Excel.Rang
e.get_Valu
e(object)'
or 'Microsoft.Office.Interop.
Excel.Rang
e.set_Valu
e(object, object)' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 98 39 InitialPriceReportingSprea
dsheet
Error 20 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Excel.Rang
e.get_Valu
e(object)'
or 'Microsoft.Office.Interop.
Excel.Rang
e.set_Valu
e(object, object)' C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 101 82 InitialPriceReportingSprea
dsheet
Error 21 No overload for method 'Close' takes '1' arguments C:\Users\Aministrator\Desk
top\Initia
lPriceRepo
rting\Init
ialPriceRe
porting\Do
tNet\Initi
alPriceRep
ortingSpre
adsheet\Pr
ogram.cs 122 17 InitialPriceReportingSprea
dsheet
Start Free Trial