I am using the Following Code to create the excel file while i execute the code the error has come the line at middle of the code(I mention seperately)
[STAThread]
protected void Generate_Click(object sender, EventArgs e)
{
int io = 0;
System.Data.DataTable workTable = new System.Data.DataTable();
workTable.TableName = "VendorList";
workTable.Columns.Add("CURRENCY_CODE");
workTable.Columns.Add("REMARKS");
workTable.Columns.Add("VENDOR_NAME");
System.Data.DataRow workRow;
objDAOUploadEnquiry.ActionType = SRCMAction.FETCH.ToString();
objBLLUploadEnquiry.SelectCommonMasterUom(objDAOUploadEnquiry);
object dropDownValues = "";
for (int y = 0; y <= 9; y++)
{
workRow = workTable.NewRow();
if (io == 0)
{
for (int kl = 0; kl < objDAOUploadEnquiry.UploadEnquriyList.Rows.Count; kl++)
{
dropDownValues += objDAOUploadEnquiry.UploadEnquriyList.Rows[kl]["TEXT_VALUE"].ToString() + ",";
}
io = 1;
}
workTable.Rows.Add(workRow);
}
string data = null;
int i = 0;
int j = 0;
int rowsCount = workTable.Rows.Count + 1;
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
object pwd = "pwd";
Excel.Application xl = null;
Excel._Workbook wb = null;
Excel._Worksheet sheet = null;
object Missing = System.Reflection.Missing.Value;
try
{
xlApp = new Excel.ApplicationClass();
xl = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
wb = (Excel._Workbook)(xl.Workbooks.Add(Missing));
wb.Sheets.Add(Missing, Missing, Missing, Missing);
sheet = (Excel._Worksheet)(wb.Sheets[1]);
xlWorkSheet.Name = "IncludeVendorList";
Excel.Range m_range = sheet.get_Range("A1", "A10");
Excel.Range _nValidationRange = xlApp.get_Range("C2", "C10");
<code>I got an error on the Following Line While i execute this code </code>
_nValidationRange.Validation.Add(Excel.XlDVType.xlValidateList, Excel.XlDVAlertStyle.xlValidAlertStop, Excel.XlFormatConditionOperator.xlBetween, dropDownValues, Type.Missing);
xlWorkBook.SaveAs(("G:\\dhinakr.xls"), Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Save();
xlApp.Quit();
xlApp.Application.Quit();
string filepath = "G:\\dhinakr.xls";
FileInfo myfile = new FileInfo(filepath);
if (myfile.Exists)
{
Response.ClearContent();
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + myfile.Name);
Response.AddHeader("Content-Length", myfile.Length.ToString());
Response.TransmitFile(myfile.FullName);
Response.End();
}
}
catch (COMException Ex)
{
GC.Collect();
throw new Exception(Ex.Message);
}
}