|
 |
|
รบกวนผู้รู้แนะนำทีครับ ผม convert excel ได้แต่ข้อมูลเข้าไม่ครบ ไม่ทราบสาเหตุช่วยแนะนำทีครับ |
|
 |
|
|
 |
 |
|

จากรูป ผมทำการแปลงไฟล์ Excel โดยกด upload file แล้วนำมาโชว์ใน Gridview แต่ข้อมูลที่ได้ไม่ตรงกับข้อมูลใน excel คือมาไม่ครบ จากภาพจะเห็นว่า ช่องสีแดงๆใน excel จะไม่เข้า Gridview ส่วนใหญ่เป็นตัวเลขที่มีขีดตรงกลาง ซึ่งผมงงมากครับว่าทำไมถึงไม่ได้ เพราะฟิลด์ข้างๆที่เป็นคำค้น กลับเข้าหมดเลย รบกวนช่วยแนะนำทีครับว่าเป็นเพราะอะไรครับ code ที่ใช่ก็ตามด้านล่างเลยครับ ขอบคุณครับ
Code
protected void Button1_Click(object sender, EventArgs e)
{
//***ส่วนของการอัพโหลดไฟล์ Excel***//
if (FileUpload1.HasFile)
{
string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
string Extension = Path.GetExtension(FileUpload1.PostedFile.FileName);
string FolderPath = ConfigurationManager.AppSettings["FolderPath"];
string FilePath = Server.MapPath(FolderPath + FileName);
FileUpload1.SaveAs(FilePath);
Import_To_Grid(FilePath, Extension, RadioButtonList1.SelectedItem.Text);
}
SqlTransaction tr = objConn.BeginTransaction();
SqlCommand cmd = objConn.CreateCommand();
}
private void Import_To_Grid(string FilePath, string Extension, string isHDR)
{
string conStr = "";
switch (Extension)
{
case ".xls": //Excel 97-03
conStr = ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString;
break;
case ".xlsx": //Excel 07
conStr = ConfigurationManager.ConnectionStrings["Excel07ConString"].ConnectionString;
break;
}
conStr = String.Format(conStr, FilePath, isHDR);
OleDbConnection connExcel = new OleDbConnection(conStr);
OleDbCommand cmdExcel = new OleDbCommand();
OleDbDataAdapter oda = new OleDbDataAdapter();
DataTable dt = new DataTable();
cmdExcel.Connection = connExcel;
//Get the name of First Sheet
connExcel.Open();
DataTable dtExcelSchema;
dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
connExcel.Close();
//Read Data from First Sheet
connExcel.Open();
cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";
oda.SelectCommand = cmdExcel;
oda.Fill(dt);
connExcel.Close();
//Bind Data to GridView #1
GridView1.Caption = Path.GetFileName(FilePath);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void PageIndexChanging(object sender, GridViewPageEventArgs e)
{
string FolderPath = ConfigurationManager.AppSettings["FolderPath"];
string FileName = GridView1.Caption;
string Extension = Path.GetExtension(FileName);
string FilePath = Server.MapPath(FolderPath + FileName);
Import_To_Grid(FilePath, Extension, RadioButtonList1.SelectedItem.Text);
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
ช่วยแนะนำด้วยนะครับ ขอบคุณล่วงหน้ามากครับ 
Tag : .NET, Web (ASP.NET), C#

|
ประวัติการแก้ไข 2013-01-08 11:36:15
|
 |
 |
 |
 |
Date :
2013-01-08 11:35:15 |
By :
SponG_Gy |
View :
1037 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมแก้ได้แล้วนะครับ ขอบคุณผู้ที่ช่วยดูนะครับ 
|
 |
 |
 |
 |
Date :
2013-01-08 14:07:55 |
By :
SponG_Gy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
จัดไปครับ
|
 |
 |
 |
 |
Date :
2013-01-08 14:49:06 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เก่งจังครับ
|
 |
 |
 |
 |
Date :
2013-01-08 21:09:02 |
By :
ERO-TIC |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|