Click here to Skip to main content
15,881,687 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: how authenticate aspnet using SQLSERVER Pin
Joshua Omundson27-Apr-12 11:09
Joshua Omundson27-Apr-12 11:09 
GeneralRe: how authenticate aspnet using SQLSERVER Pin
alsayani27-Apr-12 23:54
alsayani27-Apr-12 23:54 
AnswerRe: how authenticate aspnet using SQLSERVER Pin
Joshua Omundson3-May-12 6:09
Joshua Omundson3-May-12 6:09 
Questiondeveloping a secure asp.net application? Pin
Alok Sharma ji27-Apr-12 0:00
Alok Sharma ji27-Apr-12 0:00 
AnswerRe: developing a secure asp.net application? Pin
R. Giskard Reventlov27-Apr-12 11:17
R. Giskard Reventlov27-Apr-12 11:17 
QuestionOnline book store Project Pin
Suraj Menon26-Apr-12 17:30
Suraj Menon26-Apr-12 17:30 
AnswerRe: Online book store Project Pin
Blue_Boy26-Apr-12 22:06
Blue_Boy26-Apr-12 22:06 
QuestionHow to autofit when Export to Excel ? Pin
Tin Christina26-Apr-12 15:18
Tin Christina26-Apr-12 15:18 
First, please look at my funtion here:
It will write an excel file when datareader run.

C#
protected void ExportToExel_Click(object sender, EventArgs e)
        {
            string a = string.Format("{0:MM/dd/yyyy}", dtBeginDate.SelectedDate.Value); //get value of FromDate
            string b = string.Format("{0:MM/dd/yyyy}", dtEndDate.SelectedDate.Value); //get value of ToDate

            //call function to Read SQL database between FromDate & ToDate.
            SqlDataReader dtReader = VNPTTracking.DataAccess.Report.ReportOnlineVehicle(id, a, b);


            // Prepair to export to Excels
            HttpContext context = HttpContext.Current;
            context.Response.Clear(); 

            //Vietnamese, so I have to use this function
            context.Response.ContentEncoding = System.Text.Encoding.Unicode;             context.Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());

            // Write header in row 1 in Excels
            string[] s = { "Biển số", "Tỉnh/TP", "Khách hàng", "Tài khoản", "Mã thiết bị", "Cảm ứng dầu", "Địa chỉ hiện tại", "Thời điểm nhận tin cuối" };
            int n = 0;
            for (int i = 0; i < s.Count(); i++)
            {
                context.Response.Write(s[n] + "\t");  //get value s[n] of s matrix, add "\t" to mark position where write in next column
                n++;
            }
            context.Response.Write(Environment.NewLine); 
            
            
            while (dtReader.Read()) //run the data reader. Each line write a row in Excels
            {
                context.Response.Write(dtReader.GetValue(0) + "\t"); //Biển số
                context.Response.Write(dtReader.GetValue(1) + "\t"); //Tỉnh/TP
                context.Response.Write(dtReader.GetValue(2) + "\t"); //Khách hàng
                context.Response.Write(dtReader.GetValue(3) + "\t"); //Tài khoản
                context.Response.Write(dtReader.GetValue(4) + "\t"); //Mã thiết bị

                if (Convert.ToInt32(dtReader.GetValue(5)) == 1) //Cảm ứng dầu
                {
                    context.Response.Write("Có" + "\t");
                }
                else context.Response.Write("Không" + "\t");

                context.Response.Write(dtReader.GetValue(6) + "\t"); //Địa chỉ hiện tại
                context.Response.Write(dtReader.GetValue(7) + "\t"); //Thời điểm nhận tin cuối
               
                context.Response.Write(Environment.NewLine); 
                            
            }

            // File name
            context.Response.AddHeader("content-disposition", "attachment; filename=Report.xls");
            context.Response.ContentType = "application/ms-excel";
            context.Response.End();
  
        }


Ok, it work good, but has some problem here. That after it export, excels file like this:

http://i495.photobucket.com/albums/rr311/max_lionhart/excels.jpg

Well, the column can't auto fit & a columns has type like number will be become eg: 3,024515E+13 when it too long.

Any one have solution to fix it? Thank you!
AnswerRe: How to autofit when Export to Excel ? Pin
Joshua Omundson26-Apr-12 16:39
Joshua Omundson26-Apr-12 16:39 
Questiondeploy vs 2010 web form app Pin
dcof26-Apr-12 10:56
dcof26-Apr-12 10:56 
AnswerRe: deploy vs 2010 web form app Pin
Sandeep Mewara29-Apr-12 7:47
mveSandeep Mewara29-Apr-12 7:47 
AnswerRe: deploy vs 2010 web form app Pin
ZurdoDev30-Apr-12 10:46
professionalZurdoDev30-Apr-12 10:46 
Questiontesting 2010 web form application Pin
classy_dog26-Apr-12 2:05
classy_dog26-Apr-12 2:05 
AnswerRe: testing 2010 web form application Pin
Not Active26-Apr-12 3:03
mentorNot Active26-Apr-12 3:03 
GeneralRe: testing 2010 web form application Pin
Richard MacCutchan26-Apr-12 3:36
mveRichard MacCutchan26-Apr-12 3:36 
AnswerRe: testing 2010 web form application Pin
ZurdoDev30-Apr-12 10:47
professionalZurdoDev30-Apr-12 10:47 
QuestionConnect to Oracle database from Log4net.config file Pin
forum.forum26-Apr-12 1:22
forum.forum26-Apr-12 1:22 
AnswerRe: Connect to Oracle database from Log4net.config file Pin
Not Active26-Apr-12 3:04
mentorNot Active26-Apr-12 3:04 
QuestionCant change asp:textbox font to hindi UTF-8 ? Pin
Alok Sharma ji26-Apr-12 0:31
Alok Sharma ji26-Apr-12 0:31 
AnswerRe: Cant change asp:textbox font to hindi UTF-8 ? Pin
Alok Sharma ji3-May-12 23:57
Alok Sharma ji3-May-12 23:57 
Questioncontrol ip relay device from internet web page Pin
GAT_TECH25-Apr-12 19:55
GAT_TECH25-Apr-12 19:55 
AnswerRe: control ip relay device from internet web page Pin
ZurdoDev30-Apr-12 10:47
professionalZurdoDev30-Apr-12 10:47 
GeneralRe: control ip relay device from internet web page Pin
GAT_TECH3-May-12 3:46
GAT_TECH3-May-12 3:46 
QuestionCreating a simple search engine in asp.net Pin
Member 888549225-Apr-12 13:02
Member 888549225-Apr-12 13:02 
AnswerRe: Creating a simple search engine in asp.net PinPopular
R. Giskard Reventlov25-Apr-12 13:10
R. Giskard Reventlov25-Apr-12 13:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.