|
 |
|
(C#, Web)เกี่ยวกับการ Export Excel ครับ อยากทราบวิธี save แบบเลือกจุดที่จะ save ครับ |
|
 |
|
|
 |
 |
|
ผมได้เอาตัว web ลงเครื่องลูกค้าที่เป็นเครื่องแม่เพื่อให้เครื่องอื่น ๆ ในวง เข้ามาเรียกใช้ web แล้ว export ข้อมูลไป
ผมมีปัญหาอยู่ที่ว่าผมใช้คำสั่ง
Code (C#)
string strFileName = "D:\\Export\\" + report_name + ".xls";
xlWorkBook.SaveAs(strFileName,
mis, mis, mis, mis, mis, Excel.XlSaveAsAccessMode.xlExclusive, mis, mis, mis, mis, mis);
มัน save ไฟล์ลงเครื่องแม่อย่างเดียว ไม่ขึ้นให้เลือกที่ save
มีวิธีที่จะทำให้ขึ้นเลือกที่ save ไฟล์ไหมครับ
Tag : .NET, Web (ASP.NET), C#, VS 2008 (.NET 3.x)

|
ประวัติการแก้ไข 2012-01-17 17:45:10 2012-01-17 17:45:41 2012-01-17 17:46:07
|
 |
 |
 |
 |
Date :
2012-01-17 17:44:21 |
By :
anikus |
View :
2677 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถูกแล้วครับ Save ที่ Server จากนั้นคุณจะต้องทำเป็๋น Link ให้ User Download หรือ ส่งอีเมล์แนบเป็นไฟล์ก็ได้ครับ 
|
 |
 |
 |
 |
Date :
2012-01-17 17:57:56 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีตัวอย่าง download file ไหมครับ
ผมอยากทำให้จบในปุ่มเดียวเลย export ไฟล์เสร้จแล้ว ขึ้นให้ download ไปเลยอะครับ
ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2012-01-17 18:17:24 |
By :
anikus |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้ folderBrowserDialog ครับ แล้วเขียนโปรแกรม เก็บ path ไว้ใน textbox แล้วค่อย Export เป็น Excel ครับ

โดย ลาก folderBrowserDialog ใส่ ในหน้า Design แล้วออกแบบ โปรแกรม โดยให้มี 2 Button 1 Texbox
แล้วเขียนโปรแกรม ประมาณ นี้นะครับ
Code (C#)
private void button1_Click(object sender, EventArgs e)
{
textBox1.Clear();
folderBrowserDialog1.ShowDialog();
textBox1.Text = folderBrowserDialog1.SelectedPath + "\\" + "PharReport.xls";
}
private void button3_Click(object sender, EventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
Excel.Application xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
int i = 0;
int j = 0;
for (i = 0; i <= dataGridView1.RowCount - 1; i++)
{
for (j = 0; j <= dataGridView1.ColumnCount - 1; j++)
{
DataGridViewCell cell = dataGridView1[j, i];
xlWorkSheet.Cells[i + 1, j + 1] = cell.Value;
}
}
xlWorkBook.SaveAs(textBox1.Text, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
catch (Exception ex)
{
MessageBox.Show("การสร้างไฟล์เกิดข้อผิดพลาด กรุณาตรวจสอบอีกครั้ง" + ex.ToString());
}
finally
{
this.Cursor = Cursors.Default;
MessageBox.Show("สร้างไฟล์ที่ " + textBox1.Text + " เรียบร้อยแล้ว");
}
}
|
 |
 |
 |
 |
Date :
2012-01-18 12:08:38 |
By :
Chet |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|