usingsystem;
using
system.io;
using
system.collections.generic;
using
system.text;
using
system.data;
using
system.drawing;
using
system.windows.forms;
namespace
config
public
void
datagridviewtoxml(datagridviewexportoptions datagridviewexportoption, string filepath)
), filepath);
}public
void datagridviewtoxml(listdatagridviewexportoptions, string filepath)
i++;}}
else
datagridviewfilltodataset(dataset, option);
sheetindex++;
#endregion
} exporttoxml(dataset, filepath);
}finally
}//處理 datagridview 中的資料以填充到指定的 dataset 中
private
void
datagridviewfilltodataset(dataset dataset, datagridviewexportoptions option)
#endregion
#region " 填充**正文內容 "
foreach (datagridviewrow datarow in
option.datagridview.rows)
else
}table.rows.add(row);
}#endregion
dataset.tables.add(table);
}#endregion
#region " exporttoxml "
//////儲存 dataset 資料到 xml 檔案
///
///dataset資料物件
///xml 檔案位址
private
void
exporttoxml(dataset dataset, string filepath)
catch
#endregion
dataset.writexml(filepath);
}#endregion
#region importxml
public
void
xml2datagridview(datagridview datagridview, string filepath)}}
#endregion
}
#region " datacolumnexportoptions "
//////匯出資料字段屬性選項類
/// class
datacolumnexportoptions
set
}//////
字段標題
/// public
string caption
set
}//////
是否顯示(匯出)
/// public
boolean visible
set
}//////
建構函式
///
///欄位名稱
public
datacolumnexportoptions(string columnname)
: this
(columnname, columnname)
//////
建構函式
///
///欄位名稱
///字段標題
public
datacolumnexportoptions(string columnname, string caption)
: this(columnname, caption, true
)
//////
建構函式
///
///欄位名稱
///字段標題
///是否顯示(匯出)
public
datacolumnexportoptions(string columnname, string caption, boolean visible)
}#endregion
#region " datagridviewexportoptions 「
class
datagridviewexportoptions
set
}//////
匯出的字段屬性列表
/// public listcolumnoptions
set
}//////
要匯出的字段列表(唯讀)
/// public listvisiblecolumnoptions
}//////
匯出的工作表名稱
/// public
string worksheetname
set
}//////
建構函式
///
///要匯出到datagridview物件
public
datagridviewexportoptions(datagridview datagridview)
: this(datagridview, null
)
//////
建構函式
///
///要匯出到datagridview物件
///匯出的字段屬性列表
public datagridviewexportoptions(datagridview datagridview, listcolumnoptions)
: this(datagridview, columnoptions, null
)
//////
建構函式
///
///要匯出到datagridview物件
///匯出的字段屬性列表
///匯出生成的工作表名稱
public datagridviewexportoptions(datagridview datagridview, listcolumnoptions, string worksheetname)
else
if(string.isnullorempty(worksheetname))
this._worksheetname =datagridview.name;
else
this._worksheetname =worksheetname;
this._visiblecolumnoptions = new list();
foreach (datacolumnexportoptions option in
this
._columnoptions)}}
#endregion
}
datagridview 匯出Excel檔案
以datagridview 匯出excel檔案 public void exportexcel datagridview dgv microsoft.office.interop.excel.workbook workbook workbooks.add microsoft.office.inter...
DataGridView匯出到Excel的三個方法
region datagridview資料顯示到excel 開啟excel並將datagridview控制項中資料匯出到excel datagridview物件 是否顯示excel介面 add com microsoft excel 11.0 object library using excel m...
從 DataGridView 匯出到 Excel
public sub exporttoexcel byval datagridview1 as datagridview if datagridview1.rows.count 1 then for i 0 to datagridview1.columncount 1 生成excel中列頭名稱 my...