Có thể bạn quan tâm


Đang tải thanh công cụ tìm kiếm ...

Hiện kết quả từ 1 tới 2 của 2

code export du liệu sang excel, word, ... trong window form

Chủ đề được gửi trong chuyên mục Lập trình ứng dụng di động bởi tamphamaz


  1. 11-08-2010, 04:47 PM

    code export du liệu sang excel, word, ... trong window form

    Ai co code xuất data sang dinh dạng excel, word, access... thì share cho mình với nhé, thanks nhìu nhìu.
    Nhớ vợ thằng bạn keke

  2. 14-08-2010, 08:32 AM

    code export du liệu sang excel, word, ... trong window form

    Cái này mình tìm hiểu được rồi, cám ơn các bạn quan tâm, sẵn mình chia sẻ với các bạn luôn nhé.

    public static int Export2Excel(ListView root, string Path)
    {
    int kq = 0;
    int row = 1;

    ExcelCOM.Application exApp = new ExcelCOM.Application();
    ExcelCOM.Workbook exBook = exApp.Workbooks.Add(ExcelCOM.XlWBATemplate.xlWBATW orksheet);
    ExcelCOM.Worksheet exSheet = (ExcelCOM.Worksheet)exBook.Worksheets[1];

    //dat ten cho worksheet
    exSheet.Name = "example sheet";

    for (int i = 0; i < root.Columns.Count; i++)
    {
    exSheet.Cells[1, (i + 1)] = root.Columns[i].Text;
    }

    for (int col = 0; col < root.Items.Count; col++)
    {
    row++;
    for (int k = 0; k < root.Items[col].SubItems.Count; k++)
    {
    exSheet.Cells[row, (k + 1)] = root.Items[col].SubItems[k].Text;

    }
    }
    if (Path == "")
    {
    Path = "C:\\" + "url1.xls"; //dat duong dan
    }

    exApp.Visible = false;
    try
    {
    exBook.SaveAs(Path, ExcelCOM.XlFileFormat.xlWorkbookNormal,
    null, null, false, false,
    ExcelCOM.XlSaveAsAccessMode.xlExclusive,
    false, false, false, false, false);

    exBook.Close(false, false, false);
    exApp.Quit();
    kq = 1;
    }
    catch
    {
    kq= 0;
    }
    System.Runtime.InteropServices.Marshal.ReleaseComO bject(exBook);
    System.Runtime.InteropServices.Marshal.ReleaseComO bject(exApp);
    return kq;
    }
    Mình export từ control là Listview, bạn nào dùng cái khác hay export trực tiếp từ database thì sữa lại cho phù hợp nhé.
    Nhớ vợ thằng bạn keke


Thông tin đề tài

Users Browsing this Thread

Hiện đang có 1 người đang xem bài viết này. (0 thành viên và 1 khách)

Visitors found this page by searching for:

xuất dữ liệu ra excle word hay pdf với c#

xuat dư lieu ra word dung dong lăp for

windows CE.net code export data to excel

code form ve word

code xuất file excel trong c#

xuat du lieu ra form trong c#

xuat du lieu ra file dbf trong c#

xuat du lieu access ra excel

xuat data tu vb6 ra cell cua excel