کد تبدیل یه گزارش به فرمت اکسل

ha8i8eh

New Member
کد:
  [LEFT][COLOR=blue][FONT=&quot]protected[/FONT][/COLOR][FONT=&quot] [COLOR=blue]void[/COLOR] btnExcel_Click([COLOR=blue]object[/COLOR] sender, [COLOR=#2B91AF]EventArgs[/COLOR] e)[/FONT][/LEFT]
  [LEFT][FONT=&quot]        {[/FONT][/LEFT]
  [LEFT][FONT=&quot]            [COLOR=blue]string[/COLOR] sql = HiddenField_Sql.Value;[/FONT][/LEFT]
  [LEFT][FONT=&quot] [/FONT][/LEFT]
  [LEFT][FONT=&quot]            Microsoft.Office.Interop.Excel.[COLOR=#2B91AF]ApplicationClass[/COLOR] excel = [COLOR=blue]new[/COLOR] Microsoft.Office.Interop.Excel.[COLOR=#2B91AF]ApplicationClass[/COLOR]();[/FONT][/LEFT]
  [LEFT][FONT=&quot]            excel.Visible = [COLOR=blue]true[/COLOR];[/FONT][/LEFT]
  [LEFT][FONT=&quot]            Microsoft.Office.Interop.Excel.[COLOR=#2B91AF]Workbook[/COLOR] workbook = excel.Workbooks.Add(Microsoft.Office.Interop.Excel.[COLOR=#2B91AF]XlWBATemplate[/COLOR].xlWBATWorksheet);[/FONT][/LEFT]
  [LEFT][FONT=&quot]            Microsoft.Office.Interop.Excel.[COLOR=#2B91AF]Sheets[/COLOR] sheets = workbook.Worksheets;[/FONT][/LEFT]
  [LEFT][FONT=&quot]            Microsoft.Office.Interop.Excel.[COLOR=#2B91AF]Worksheet[/COLOR] mySheet = (Microsoft.Office.Interop.Excel.[COLOR=#2B91AF]Worksheet[/COLOR])sheets.get_Item([COLOR=#A31515]"Sheet1"[/COLOR]);[/FONT][/LEFT]
  [LEFT][FONT=&quot]            mySheet.DisplayRightToLeft = [COLOR=blue]true[/COLOR];[/FONT][/LEFT]
  [LEFT][FONT=&quot]            mySheet.Rows.Font.Name = [COLOR=#A31515]"tahoma"[/COLOR];[/FONT][/LEFT]
  [LEFT][FONT=&quot] [/FONT][/LEFT]
  [LEFT][FONT=&quot]            Microsoft.Office.Interop.Excel.[COLOR=#2B91AF]Range[/COLOR] myRng;[/FONT][/LEFT]
  [LEFT][FONT=&quot]            myRng = (Microsoft.Office.Interop.Excel.[COLOR=#2B91AF]Range[/COLOR])mySheet.get_Range([COLOR=#A31515]"A1"[/COLOR], [COLOR=#A31515]"G1"[/COLOR]);[/FONT][/LEFT]
  [LEFT][FONT=&quot]            myRng.Merge([COLOR=blue]true[/COLOR]);[/FONT][/LEFT]
  [LEFT][FONT=&quot]            myRng.Font.Bold = [COLOR=blue]true[/COLOR];[/FONT][/LEFT]
  [LEFT][FONT=&quot]            myRng = (Microsoft.Office.Interop.Excel.[COLOR=#2B91AF]Range[/COLOR])mySheet.get_Range([COLOR=#A31515]"A2"[/COLOR], [COLOR=#A31515]"G2"[/COLOR]);[/FONT][/LEFT]
  [LEFT][FONT=&quot]            myRng.Font.Bold = [COLOR=blue]true[/COLOR];[/FONT][/LEFT]
  [LEFT][COLOR=green][FONT=&quot] [/FONT][/COLOR][/LEFT]
  [LEFT][COLOR=green][FONT=&quot] [/FONT][/COLOR][/LEFT]
  [LEFT][FONT=&quot]            [COLOR=blue]int[/COLOR] RowIndex = 1;[/FONT][/LEFT]
  [LEFT][FONT=&quot]            [COLOR=blue]string[/COLOR] headerText;[/FONT][/LEFT]
  [LEFT][FONT=&quot]            headerText = [COLOR=#A31515]"گزارشات لاگ من"[/COLOR];[/FONT][/LEFT]
  [LEFT][FONT=&quot]            mySheet.Cells[RowIndex, 1] = headerText;[/FONT][/LEFT]
  [LEFT][FONT=&quot]            RowIndex++;[/FONT][/LEFT]
  [LEFT][FONT=&quot]            [COLOR=blue]string[/COLOR] connStr = [COLOR=#2B91AF]ConfigurationManager[/COLOR].AppSettings[[COLOR=#A31515]"ConnectionString"[/COLOR]];[/FONT][/LEFT]
  [LEFT][FONT=&quot]            [COLOR=#2B91AF]SqlConnection[/COLOR] sqlConn = [COLOR=blue]new[/COLOR] [COLOR=#2B91AF]SqlConnection[/COLOR](connStr);[/FONT][/LEFT]
  [LEFT][FONT=&quot]            [COLOR=#2B91AF]SqlCommand[/COLOR] sqlCmnd = [COLOR=blue]new[/COLOR] [COLOR=#2B91AF]SqlCommand[/COLOR](sql, sqlConn);[/FONT][/LEFT]
  [LEFT][FONT=&quot]            sqlConn.Open();[/FONT][/LEFT]
  [LEFT][FONT=&quot]            [COLOR=#2B91AF]SqlDataReader[/COLOR] dr = sqlCmnd.ExecuteReader();[/FONT][/LEFT]
  [LEFT][FONT=&quot]            mySheet.Cells[RowIndex, 1] = [COLOR=#A31515]"نام"[/COLOR];[/FONT][/LEFT]
  [LEFT][FONT=&quot]            mySheet.Cells[RowIndex, 2] = [COLOR=#A31515]"تاریخ رزرو"[/COLOR];[/FONT][/LEFT]
  [LEFT][FONT=&quot]            mySheet.Cells[RowIndex, 3] = [COLOR=#A31515]"ساعت رزور"[/COLOR];[/FONT][/LEFT]
  [LEFT][FONT=&quot]            mySheet.Cells[RowIndex, 4] = [COLOR=#A31515]"برنامه غذایی"[/COLOR];[/FONT][/LEFT]
  [LEFT][FONT=&quot]            mySheet.Cells[RowIndex, 5] = [COLOR=#A31515]"قیمت غذا"[/COLOR];[/FONT][/LEFT]
  [LEFT][FONT=&quot]            mySheet.Cells[RowIndex, 6] = [COLOR=#A31515]"نام غذا"[/COLOR];[/FONT][/LEFT]
  [LEFT][FONT=&quot]            mySheet.Cells[RowIndex, 7] = [COLOR=#A31515]"وضعیت"[/COLOR];[/FONT][/LEFT]
  [LEFT][FONT=&quot] [/FONT][/LEFT]
  [LEFT][FONT=&quot] [/FONT][/LEFT]
  [LEFT][FONT=&quot]            [COLOR=blue]while[/COLOR] (dr.Read())[/FONT][/LEFT]
  [LEFT][FONT=&quot]            {[/FONT][/LEFT]
  [LEFT][FONT=&quot]                RowIndex++;[/FONT][/LEFT]
  [LEFT][FONT=&quot] [/FONT][/LEFT]
  [LEFT][FONT=&quot]                mySheet.Cells[RowIndex, 1] = dr[[COLOR=#A31515]"urName"[/COLOR]].ToString();[/FONT][/LEFT]
  [LEFT][FONT=&quot]                mySheet.Cells[RowIndex, 2] = dr[[COLOR=#A31515]"lgDate"[/COLOR]].ToString();[/FONT][/LEFT]
  [LEFT][FONT=&quot]                mySheet.Cells[RowIndex, 3] = dr[[COLOR=#A31515]"lgTime"[/COLOR]].ToString();[/FONT][/LEFT]
  [LEFT][FONT=&quot]                mySheet.Cells[RowIndex, 4] = dr[[COLOR=#A31515]"dyDate"[/COLOR]].ToString();[/FONT][/LEFT]
  [LEFT][FONT=&quot]                mySheet.Cells[RowIndex, 5] = [COLOR=blue]int[/COLOR].Parse(dr[[COLOR=#A31515]"dyMyPrice"[/COLOR]].ToString());[/FONT][/LEFT]
  [LEFT][FONT=&quot]                mySheet.Cells[RowIndex, 6] = dr[[COLOR=#A31515]"fdName"[/COLOR]].ToString();[/FONT][/LEFT]
  [LEFT][FONT=&quot]                mySheet.Cells[RowIndex, 7] = [COLOR=blue]int[/COLOR].Parse(dr[[COLOR=#A31515]"lgStatus"[/COLOR]].ToString());[/FONT][/LEFT]
  [LEFT][FONT=&quot] [/FONT][/LEFT]
  [LEFT][FONT=&quot] [/FONT][/LEFT]
  [LEFT][FONT=&quot]            }[/FONT][/LEFT]
  [LEFT][FONT=&quot]            sqlConn.Close();[/FONT][/LEFT]
  [FONT=&quot]        }[/FONT][FONT=&quot][/FONT]
  [FONT=&quot] [/FONT]

[FONT=&quot]وقتی از طریق سورس برنامه رو اجرا میکنم اجرا میشه و به من خروجی اکسل رو میده ولی وقتی برنامه رو روی سرور [/FONT][FONT=&quot]publish [/FONT][FONT=&quot] میکنم به من خطا میده[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]تو اینترنت سرچ کردم و راه حل رو پیدا کردم.[/FONT]
[FONT=&quot]من بر اساس فروم زیر اقدام کردم[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]http://forums.asp.net/p/1303594/3068584.aspx[/FONT][FONT=&quot][/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]ولی باز هم خطا میده و اجرا نمیشه[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]با استفاده از این کد کاربر جاری مشخص میشود[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]TextBox1.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name;[/FONT][FONT=&quot][/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]که برای [/FONT][FONT=&quot] web application [/FONT][FONT=&quot]من [/FONT]
[FONT=&quot]NT AUTHORITY\NETWORK SERVICE[/FONT][FONT=&quot][/FONT]
[FONT=&quot]بود[/FONT]
[FONT=&quot] [/FONT]
کسی میتونه راهنمایی کنه؟؟:rose:
 

جدیدترین ارسال ها

بالا