Skip to content

to excel #919

Closed
Closed

Description

@itg-assistant

roni neri asked 2017-06-27 08:43:42 UTC

Hi, I need to export my datagridview to excel; is there something I can use for that? I installed AccessDatabaseEngine to use

interp.excel but the application not start with this reference.

Activity

  1. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2017-06-27 16:03:37 UTC

    You can use the built-in DataGridView.GetClipboardContent(), it will return HTML that can be opened by Excel. Look also at ClipboardCopyMode:

    http://wisej.com/docs/html/P_Wisej_Web_DataGridView_ClipboardCopyMode.htm

    http://wisej.com/docs/html/M_Wisej_Web_DataGridView_GetClipboardContent.htm

    Here is a video showing the same functionality copied to excel:

    http://www.screencast.com/t/76izqzD8F

  2. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    edmond girardi answered 2017-06-27 16:53:37 UTC

    You can use ClosedXML:

    https://github.com/ClosedXML/ClosedXML

    Lots of examples if you Google it. This will create actual Excel or Word documents.

  3. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    roni neri answered 2017-07-04 16:44:14 UTC

    I cannot copy the grid in clipboard; I would like to use some examples because it seems that the grid is not enabled to do so

  4. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    roni neri answered 2017-07-05 13:51:34 UTC

    With the NPOI classes I managed to create a "stream" of datagridview and download it as xls file

  5. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    preecha wanlor answered 2017-08-31 14:17:57 UTC

    You can use ExcelLibrary.dll from  https://code.google.com/archive/p/excellibrary/downloads

    and use code to export .xls file

    string filename = HttpContext.Current.Server.MapPath("export.xls");

    DataTable dt = new DataTable();
    foreach (DataGridViewColumn col in dataGridView1.Columns)
    {
    dt.Columns.Add(col.HeaderText);
    }

    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
    DataRow dRow = dt.NewRow();
    foreach (DataGridViewCell cell in row.Cells)
    {
    if (cell.Value != null)
    {
    dRow[cell.ColumnIndex] = cell.Value.ToString();
    }else
    {
    dRow[cell.ColumnIndex] = "";
    }
    }
    dt.Rows.Add(dRow);
    }

    DataSet ds1 = new DataSet();
    ds1.Tables.Add(dt);
    ds1.Locale = System.Threading.Thread.CurrentThread.CurrentCulture;

    //Here's the easy part. Create the Excel worksheet from the data set
    ExcelLibrary.DataSetHelper.CreateWorkbook(filename, ds1);

    Application.Download(filename);

    ขอบคุณครับ

  6. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Saqıp answered 2018-06-19 16:42:00 UTC

    https://github.com/ClosedXML/ClosedXML         is not work on  wisej  , wisej is closedxml support ?

    Thanks

  7. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2018-06-19 18:48:55 UTC

    Works fine. Any .NET library works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GeneralQuestions, how-tos and everything else.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions