|
|
|
อยากทราบการดึงไฟล์ excel เข้ามาใช้ใน asp.net c# อ่ะค่ะ |
|
|
|
|
|
|
|
Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ExcelC
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnExcel_Click(object sender, EventArgs e)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object mis = Type.Missing;
string strFileName = "C:\\ExcelC\\Xls\\csharp-Excel.xls";
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(mis);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.Add(1);
xlWorkSheet.Name = "My Sheet2";
xlWorkSheet.Cells[1, 1] = "Test.Com";
xlWorkBook.SaveAs(strFileName,
mis, mis, mis, mis, mis, Excel.XlSaveAsAccessMode.xlExclusive, mis, mis, mis, mis, mis);
xlWorkBook.Close(true, strFileName, mis);
xlApp.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkBook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkSheet);
GC.Collect();
MessageBox.Show("c:\\my-Excel.xls");
}
}
}
|
|
|
|
|
Date :
2011-08-10 19:38:35 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|