mathieu_cupryk
asked on
small excell conversion from vb.net to c#.
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
private void ProcessSpreadsheet(string filename)
{
Microsoft.Office.Interop.E
// Excel application object
Microsoft.Office.Interop.E
// Excel Workbook object
Microsoft.Office.Interop.E
// Excel Worksheet object
Microsoft.Office.Interop.E
// 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
double[,] discounts = new double[5, 4];
int pricesColumn;
// Define the input SS and open the 1st worksheet
xlApp = new Microsoft.Office.Interop.E
xlWorkBook = xlApp.Workbooks.Open(filen
xlWorkSheet = (Microsoft.Office.Interop.
// 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.
if (Strings.Len(cellvalue.Val
{
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.
gradeName = cellvalue.Value.ToString;
Insert_Price_List_Detail(g
// insert the prices
}
}
catch
{
Console.WriteLine("Excepti
}
}
// Process discounts
for (rowCount = currRow; rowCount <= currRow + 3; rowCount++)
{
// Read the discounts
try
{
cellvalue = (Microsoft.Office.Interop.
if (Strings.Len(cellvalue.Val
{
discounts[rowCount - currRow, 0] = (double)cellvalue.Value;
cellvalue = (Microsoft.Office.Interop.
discounts[rowCount - currRow, 1] = (double)cellvalue.Value;
cellvalue = (Microsoft.Office.Interop.
if (cellvalue.Value.ToString != "N/A")
{
// Des Barley is the last discount
discounts[rowCount - currRow, 2] = (double)cellvalue.Value;
Update_Price_List_Header_w
// save the discounts
break; // TODO: might not be correct. Was : Exit For
}
else
{
discounts[rowCount - currRow, 2] = 0;
}
}
}
catch
{
Console.WriteLine("Excepti
}
}
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
Error 2 Property, indexer, or event 'Item' is not supported by the language; try directly calling accessor method 'Microsoft.Office.Interop.
Error 3 The name 'initialButton' does not exist in the current context C:\Users\Aministrator\Desk
Error 4 'Microsoft.Office.Interop.
Error 5 The name 'Strings' does not exist in the current context C:\Users\Aministrator\Desk
Error 6 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Error 7 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Error 8 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Error 9 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Error 10 'Microsoft.Office.Interop.
Error 11 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Error 12 'Microsoft.Office.Interop.
Error 13 The name 'Strings' does not exist in the current context C:\Users\Aministrator\Desk
Error 14 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Error 15 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Error 16 'Microsoft.Office.Interop.
Error 17 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Error 18 'Microsoft.Office.Interop.
Error 19 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Error 20 Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.
Error 21 No overload for method 'Close' takes '1' arguments C:\Users\Aministrator\Desk
Private Sub Open_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
Dim xlApp As Excel.Application ' Excel application object
Dim xlWorkBook As Excel.Workbook ' Excel Workbook object
Dim xlWorkSheet As Excel.Worksheet ' Excel Worksheet object
Dim inputRange As Excel.Range ' Excel Worksheet Range object
Dim rowCount, currRow As Integer ' row iterator
Dim gradeName As String ' character input variables
Dim Price As Double ' price as a decimal number
Dim cellvalue As Excel.Range
Dim discounts(4, 3) As Double
Dim pricesColumn As Integer
' Define the input SS and open the 1st worksheet
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open(txtFileInput.Text)
xlWorkSheet = CType(xlWorkBook.Worksheets.Item(1), Excel.Worksheet)
' 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 To inputRange.Rows.Count
' 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 Then
pricesColumn = 16
Else
pricesColumn = 18
End If
cellvalue = CType(inputRange.Cells(rowCount, pricesColumn), Excel.Range)
If Len(cellvalue.Value) > 0 Then
If cellvalue.Value.ToString = "Stones" Or cellvalue.Value.ToString = "Tough" Then ' all prices have been read
currRow = rowCount + 1 ' skip a row to where the discounts are
Exit For
End If
Price = CDbl(cellvalue.Value)
cellvalue = CType(inputRange.Cells(rowCount, 15), Excel.Range)
gradeName = cellvalue.Value.ToString
Insert_Price_List_Detail(gradeName, Price) ' insert the prices
End If
Catch
Console.WriteLine("Exception has occurred.")
End Try
Next
' Process discounts
For rowCount = currRow To currRow + 3
' Read the discounts
Try
cellvalue = CType(inputRange.Cells(rowCount, 16), Excel.Range)
If Len(cellvalue.Value) > 0 Then
discounts(rowCount - currRow, 0) = CDbl(cellvalue.Value)
cellvalue = CType(inputRange.Cells(rowCount, 17), Excel.Range)
discounts(rowCount - currRow, 1) = CDbl(cellvalue.Value)
cellvalue = CType(inputRange.Cells(rowCount, 18), Excel.Range)
If cellvalue.Value.ToString <> "N/A" Then ' Des Barley is the last discount
discounts(rowCount - currRow, 2) = CDbl(cellvalue.Value)
Update_Price_List_Header_with_Discounts(discounts) ' save the discounts
Exit For
Else
discounts(rowCount - currRow, 2) = 0
End If
End If
Catch
Console.WriteLine("Exception has occurred.")
End Try
Next
inputRange = Nothing
xlWorkSheet = Nothing
If xlWorkBook IsNot Nothing Then
xlWorkBook.Close(False)
End If
xlWorkBook = Nothing
If xlApp IsNot Nothing Then
xlApp.Quit()
End If
xlApp = Nothing
' Disable the "Open" button, so the user knows the file has been
' processed
btnOpen.Enabled = False
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
yep.. i copied and changed the lines with error :-)
ASKER
is there errors below:
private void ProcessSpreadsheet(string filename, string LoadTypeName)
{
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=0;
// row iterator
string gradeName;
// character input variables
int Price;
// price as a decimal number
Microsoft.Office.Interop.E xcel.Range cellvalue;
Microsoft.Office.Interop.E xcel.Range Cells;
int[,] discounts = new int[5, 4];
int pricesColumn = 0;
// Define the input SS and open the 1st worksheet
xlApp = new Microsoft.Office.Interop.E xcel.Appli cation();
xlWorkBook = xlApp.Workbooks.Open(filen ame, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
xlWorkSheet = (Microsoft.Office.Interop. Excel.Work sheet)xlWo rkBook.Wor ksheets.ge t_Item(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
// Initial prices load file has the prices in column 16
// All other load files have their prices in column 18
switch (LoadTypeName)
{
case "Initial": pricesColumn = 16; break;
case "Adjustment": pricesColumn = 18; break;
}
try
{
cellvalue = (Microsoft.Office.Interop. Excel.Rang e)inputRan ge.Cells[r owCount, pricesColumn];
if (cellvalue.ToString().Leng th > 0)
{
if (cellvalue.ToString() == "Stones" | cellvalue.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 = Int32.Parse(cellvalue.Valu e2.ToStrin g());
cellvalue = (Microsoft.Office.Interop. Excel.Rang e)inputRan ge.Cells[r owCount, 15];
gradeName = cellvalue.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 (cellvalue.Value2.ToString ().Length > 0)
{
discounts[rowCount - currRow, 0] = (int)cellvalue.Value2;
cellvalue = (Microsoft.Office.Interop. Excel.Rang e)inputRan ge.Cells[r owCount, 17];
discounts[rowCount - currRow, 1] = (int)cellvalue.Value2;
cellvalue = (Microsoft.Office.Interop. Excel.Rang e)inputRan ge.Cells[r owCount, 18];
if (cellvalue.Value2.ToString () != "N/A")
{
// Des Barley is the last discount
discounts[rowCount - currRow, 2] = (int)cellvalue.Value2;
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,Typ e.Missing, Type.Missi ng);
}
xlWorkBook = null;
if (xlApp != null)
{
xlApp.Quit();
}
xlApp = null;
}
private void ProcessSpreadsheet(string filename, string LoadTypeName)
{
Microsoft.Office.Interop.E
// Excel application object
Microsoft.Office.Interop.E
// Excel Workbook object
Microsoft.Office.Interop.E
// Excel Worksheet object
Microsoft.Office.Interop.E
// Excel Worksheet Range object
int rowCount;
int currRow=0;
// row iterator
string gradeName;
// character input variables
int Price;
// price as a decimal number
Microsoft.Office.Interop.E
Microsoft.Office.Interop.E
int[,] discounts = new int[5, 4];
int pricesColumn = 0;
// Define the input SS and open the 1st worksheet
xlApp = new Microsoft.Office.Interop.E
xlWorkBook = xlApp.Workbooks.Open(filen
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
xlWorkSheet = (Microsoft.Office.Interop.
// 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
// Initial prices load file has the prices in column 16
// All other load files have their prices in column 18
switch (LoadTypeName)
{
case "Initial": pricesColumn = 16; break;
case "Adjustment": pricesColumn = 18; break;
}
try
{
cellvalue = (Microsoft.Office.Interop.
if (cellvalue.ToString().Leng
{
if (cellvalue.ToString() == "Stones" | cellvalue.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 = Int32.Parse(cellvalue.Valu
cellvalue = (Microsoft.Office.Interop.
gradeName = cellvalue.ToString();
Insert_Price_List_Detail(g
// insert the prices
}
}
catch
{
Console.WriteLine("Excepti
}
}
// Process discounts
for (rowCount = currRow; rowCount <= currRow + 3; rowCount++)
{
// Read the discounts
try
{
cellvalue = (Microsoft.Office.Interop.
if (cellvalue.Value2.ToString
{
discounts[rowCount - currRow, 0] = (int)cellvalue.Value2;
cellvalue = (Microsoft.Office.Interop.
discounts[rowCount - currRow, 1] = (int)cellvalue.Value2;
cellvalue = (Microsoft.Office.Interop.
if (cellvalue.Value2.ToString
{
// Des Barley is the last discount
discounts[rowCount - currRow, 2] = (int)cellvalue.Value2;
Update_Price_List_Header_w
// save the discounts
break; // TODO: might not be correct. Was : Exit For
}
else
{
discounts[rowCount - currRow, 2] = 0;
}
}
}
catch
{
Console.WriteLine("Excepti
}
}
inputRange = null;
xlWorkSheet = null;
if (xlWorkBook != null)
{
xlWorkBook.Close(false,Typ
}
xlWorkBook = null;
if (xlApp != null)
{
xlApp.Quit();
}
xlApp = null;
}
no.. i think..why giving u any error ?
ASKER
cool
ASKER