I have a C# web form, that a user enters a part numbers and a quantity on, then selects a button. Ideally, I want to search the excel file for the part that was entered, then add the quantity specified by the user.
The excel file is a static list of all parts that can be entered. I'm just testing the code, so for testing I'm just changing the color of the text and making it bold if its found...
Now, I'm getting the error...
"'HttpApplicationState' does not contain a definition for 'get_Range' and no extension method 'get_Range' accepting a first argument of type 'HttpApplicationState' could be found (are you missing a using directive or an assembly reference?) CSMP_Bid_Registration C:\BPR Projects\CSMP Registration\CSMP_Registration_1_03\CSMP_Bid_Registration\Create.aspx.cs 452 Active"
protected void btnSearchRequest_Click(object sender, EventArgs e)
{
//Microsoft.Office.Interop.Excel.Range currentFind = null;
Microsoft.Office.Interop.Excel.Range firstFind = null;
object False = false;
object True = true;
_Application excel = new Microsoft.Office.Interop.Excel.Application();
String _Created = DateTime.Now.ToString("MM-dd-yy");
string _reportName = " CSMP Pricing Workbook " + CustomerLookup.CustomerName + " " + _Created + ".xlsm";
string fileName = "C:\\BPR Projects\\CSMP Registration\\CSMP_Registration_1_03\\CSMP_Bid_Registration\\UploadedFiles\\CSMP.xlsx";
Microsoft.Office.Interop.Excel.Workbook wb = excel.Workbooks._Open(@fileName, False, False, Missing.Value, Missing.Value, False, False, Missing.Value, Missing.Value, False, Missing.Value, Missing.Value, True);
Aspose.Cells.Workbook _book = new Aspose.Cells.Workbook(fileName);
//Aspose.Cells.Worksheet _sheet = _book.Worksheets[2];
_Worksheet ws = (_Worksheet)wb.Worksheets[2];
string from = "A1";
string to = "A999";
Range rng = ws.get_Range(from, to);
Range currentFind = rng.Find("8460B001AA", Missing.Value, XlFindLookIn.xlValues, Missing.Value, Missing.Value, XlSearchDirection.xlNext, False, False, Missing.Value);
currentFind.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
currentFind.Font.Bold = true;
currentFind = currentFind.FindNext(currentFind);
while (currentFind != null)
{
Keep track of the first range you find.
if (currentFind == null)
{
currentFind = currentFind;
}
// If you didn't move to a new range, you are done.
else if (currentFind.get_Address(Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1)
== currentFind.get_Address(Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1))
{
break;
}
currentFind.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
currentFind.Font.Bold = true;
currentFind = currentFind.FindNext(currentFind);
}
_book.Save(HttpContext.Current.Response, _reportName, Aspose.Cells.ContentDisposition.Attachment, new Aspose.Cells.XlsSaveOptions(Aspose.Cells.SaveFormat.Xlsm));
}