Export ONLY selected cells

Technical support for Spire.DataExport

Moderators: iceblue support, DataExport, Manager

Export ONLY selected cells

Postby gacanepa » Thu Jul 21, 2011 7:05 pm

Is it possible to export only the selected cells from a datagrid?
gacanepa
 
Posts: 8
Joined: Thu Jul 21, 2011 2:59 pm

Re: Export ONLY selected cells

Postby Justin Weng » Fri Jul 22, 2011 1:47 am

Dear gacanepa,
Thanks for your inquiry.
It's OK to do so.
You should record what you selected cells to a DataTable.
Code: Select all
this.cellExport1.DataSource = Common.ExportSource.DataTable;
            this.cellExport1.DataTable=//the dataTable you recorded
Justin
Technical Support / Developer,
e-iceblue Support Team
User avatar
Justin Weng
 
Posts: 110
Joined: Mon Mar 28, 2011 5:54 am

Re: Export ONLY selected cells

Postby gacanepa » Fri Jul 22, 2011 12:15 pm

Justin Weng wrote:Dear gacanepa,
Thanks for your inquiry.
It's OK to do so.
You should record what you selected cells to a DataTable.
Code: Select all
this.cellExport1.DataSource = Common.ExportSource.DataTable;
            this.cellExport1.DataTable=//the dataTable you recorded

Thank YOU for your kind and quick response. I think I was not very clear about what I needed.
I have a datagrid where I load an excel file. Then I want to select certain rows of that datagrid and export ONLY selected cells to a .dbf file. I got working the exporting part for the whole file that is loaded into the datagrid, but I would like to be able to export only the records that I will select.
Here's my code:
Code: Select all
        private void btnExport_Click(object sender, EventArgs e)
        {
            Spire.DataExport.DBF.DBFExport DBFExport = new Spire.DataExport.DBF.DBFExport();
            DBFExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
            DBFExport.DataTable = this.dataGridView1.DataSource as DataTable;
            DBFExport.DefaultFloatDecimal = 3;
            DBFExport.ExportIfEmpty = true;
            DBFExport.ActionAfterExport = Spire.DataExport.Common.ActionType.OpenView;
            DBFExport.AutoFitColWidth = true;
            DBFExport.FileName = "C:\\primdb.dbf";
            DBFExport.SaveToFile();
        }

I will appreciate any hint or suggestions you can provide.
Thanks again!
gacanepa
 
Posts: 8
Joined: Thu Jul 21, 2011 2:59 pm

Re: Export ONLY selected cells

Postby Justin Weng » Mon Jul 25, 2011 5:04 am

Dear gacanepa,
Thanks for your inquiry.
I don't think you understand what I mean.
In order to elaborate further on what I mean, I give you a sample code.
Code: Select all
    DataTable table = new DataTable();
            foreach (GridViewRow row in this.GridView1.Rows)
            {
                CheckBox cb = (CheckBox)row.FindControl("cbSelect");
                if (cb.Checked)
                {
                    table.Rows.Add(row);
                 }
            }
DBFExport.DataTable = table;
Justin
Technical Support / Developer,
e-iceblue Support Team
User avatar
Justin Weng
 
Posts: 110
Joined: Mon Mar 28, 2011 5:54 am


Return to Spire.DataExport

Who is online

Users browsing this forum: No registered users and 0 guests