rd shinde

rd shinde

  • NA
  • 4
  • 3k

export to excel in asp.net

Apr 14 2014 1:24 AM
ExcelApp.Application.Workbooks.Add(Type.Missing);
ExcelApp.Visible = true;
xlWorkBook = ExcelApp.Workbooks.Add();
sh = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.Add();

//xlWorkSheet = xlWorkBook.Worksheets.Add();
// xlWo
sh = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.ActiveSheet;
//Microsoft.Office.Interop.Excel.Worksheet sh = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Sheets["Mining"];
ExcelApp.Cells[1, 3] = "???? ???? ?????";

ExcelApp.Cells[2, 2] = "???? ?????:-";

Excel.Range range = sh.get_Range(sh.Cells[2, 2], sh.Cells[2, 3]);
range.WrapText = false;
range.Merge(true);
range.Font.Bold = true;
range.RowHeight = 35;
ExcelApp.Cells[2, 4] = dt1.Rows[1]["plotname"].ToString();
Excel.Range range1 = sh.get_Range(sh.Cells[2, 4], sh.Cells[2, 6]);
range1.Merge(true);
range1.WrapText = true;

ExcelApp.Cells[3, 2] = "????????? ???";
Excel.Range range2 = sh.get_Range(sh.Cells[3, 2], sh.Cells[3, 3]);
range2.Merge(true);
range2.Font.Bold = true;
range2.WrapText = true;
ExcelApp.Cells[3, 4] = dt1.Rows[1]["OwnerName"].ToString();
Excel.Range range3 = sh.get_Range(sh.Cells[3, 4], sh.Cells[3, 6]);
range3.Merge(true);
range3.WrapText = true;

ExcelApp.Cells[4, 2] = "??????";
Excel.Range range21 = sh.get_Range(sh.Cells[4, 2], sh.Cells[4, 2]);

range21.Font.Bold = true;
ExcelApp.Cells[4, 3] = ddlTaluka.SelectedItem.ToString();
ExcelApp.Cells[4, 4] = "??????";
Excel.Range range22 = sh.get_Range(sh.Cells[4, 4], sh.Cells[4, 4]);

range22.Font.Bold = true;
ExcelApp.Cells[4, 5] = ddlDistrict.SelectedItem.ToString();

// ExcelApp.Cells[5, 2] = "???? ???? ????? ?? "+txtFromDate.Text+" ????? "+ txtToDate.Text + " ??????";
Excel.Range range4 = sh.get_Range(sh.Cells[5, 2], sh.Cells[5, 6]);
range4.Value = "???? ???? ????? ?? " + txtFromDate.Text + " ????? " + txtToDate.Text + " ??????";
range4.Merge(true);

//Excel.Range rangeBorder = sh.get_Range(sh.Cells[2, 2], sh.Cells[6, 6]);
//rangeBorder.BorderAround2(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlHairline, Excel.XlColorIndex.xlColorIndexAutomatic, Excel.XlColorIndex.xlColorIndexAutomatic);
//rangeBorder.Borders.Color = System.Drawing.Color.Black.ToArgb();
//rangeBorder.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
//rangeBorder.Borders.Weight = 1d;

sh.Cells[8, 1] = "???.???";
sh.Cells[8, 2] = "??????";
sh.Cells[8, 3] = "Invoice No";
sh.Cells[8, 4] = "???? ???";
sh.Cells[8, 5] = "?????? ??????(?????)";
sh.Cells[8, 6] = "???????? ???";
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
sh.Cells[i + 9, j + 1] = dt.Rows[i][j].ToString();
//.ExcelApp.Cells[i + 3, j + 1] = dt.Rows[i][j].ToString();
Excel.Range rn = sh.get_Range(sh.Cells[8, 1], sh.Cells[i + 9, 6]);
// Microsoft.Office.Interop.Excel.Range range123 = xlWorkSheet.get_Range("A" + i + ":l9", Type.Missing);
rn.BorderAround();
rn.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlContinuous;
//rn.BorderAround2(Excel.XlLineStyle.xlContinuous, Excel.XlBorderWeight.xlHairline, Excel.XlColorIndex.xlColorIndexAutomatic, Excel.XlColorIndex.xlColorIndexAutomatic);
//rn.Borders.Color = System.Drawing.Color.Black.ToArgb();
//rn.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;

// rn.Borders.Weight = 1d;
}
}
Excel.Range rng = sh.get_Range("ai:fj");
rng.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
Excel.Range rng1 = sh.get_Range(sh.Cells[8, 1], sh.Cells[8, 6]);
rng1.WrapText = true;
rng1.Font.Bold = true;
rng1.BorderAround();
rng1.Borders.LineStyle = Microsoft.Office.Interop.Excel.XlLineStyle.xlDouble;
//Excel.Range rng1 = sh.get_Range("c2:c2");
//rng1.WrapText = false;

Excel.Range rng2 = sh.get_Range("A1:F1");
rng2.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
rng2.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.LightSteelBlue);
ExcelApp.Columns.AutoFit();
ExcelApp.ActiveWorkbook.SaveCopyAs("c:\\Mining.xls");
ExcelApp.ActiveWorkbook.Saved = true;
ExcelApp.Quit();
ScriptManager.RegisterClientScriptBlock(btnSubmit, this.GetType(), "AlertMsg", "<script language='javascript'>alert('c:\\Mining.xls');</script>", false);

The code is work properly when i used on local machine....
 
But when i deployed this code as it is with add reference of office.dll, Microsoft.Office.Interop.Excel files on server it should not work...
Please help..
 
 

Answers (1)