急~~~在线等 excel导入导出问题(导出有乱码)

来源:百度知道 编辑:UC知道 时间:2024/06/06 08:05:46
if (sfDialog.ShowDialog() == DialogResult.OK)
{
write = new StreamWriter(sfDialog.FileName, true);
string title = csvTitle();
string content = null;
write.Write(title);
for (int i = 0; i < this.dataGridView1.RowCount-1; i++)
{
for (int j = 0; j < this.dataGridView1.ColumnCount; j++)
{
if (j == this.dataGridView1.ColumnCount - 1)
{
content = this.dataGridView1.Rows[i].Cells[j].Value.ToString();
write.Flush();
}
else
{
content = this.dataGridView1.Rows[i].Cells[j].Value + ",";

拷过去直接用. 用导入返回的DATATBLE绑定到DATAGRIDVIEW控件.

/// <summary>
///使用OLEDB方式读写Excel,不需要Office组件支持
/// </summary>
class IOIEExcel
{
/************************************************************************************************************************
*
* /// 本人的Excel导入导出方法有以下特色:
///1、使用OLEDB方式读写Excel,不需要Office组件支持;
///2、支持导入导出时进度条(ProgressBar);
///3、可以将本地DataSet中的数据类型转换为对应的OleDB的数据类型导出,使导出的数据区分开时间、数字、字符串,而不是像上一版中一样全是字符串;
///4、修正了Excel2003中某些工作薄名称为汉字的表无法正确识别的BUG
///5、删除了一个无用的方法GetFirstSheetName,本方法用于获取第一个工作薄的表明,一点用没有。
*
* **********************************************************************************************************************/

/// <summary>
/// 获取链接字符串
/// </summary>
/// <param name="strFilePath"></param>
/// <returns></returns>
public static string GetExcelConnection(string strFilePath