//填充数据集
my_Adapter.Fill(my_Ds, my_TableName);
}
catch (Exception ex)
{
MessageBox.Show("选择文件格式不正确,请选择.dbf文件!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return my_Ds;
}
#endregions
#region 把数据文件导入到.xls文件
public void ExportToExcel(DataSet ds)
{
if (ds.Tables.Count != 0)
{
//创建excel文件
Microsoft.Office.Interop.Excel.Application myExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();
//打开已有的文件
Microsoft.Office.Interop.Excel.Workbook xBook = myExcel.Workbooks._Open(txtPath.Text , Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
//指定要操作的sheet
Microsoft.Office.Interop.Excel.Worksheet xSheet = (Microsoft.Office.Interop.Excel.Worksheet)xBook.Sheets[1];
#region 改成中文列名
xSheet.Cells[1, 1] = "程序员";
.
.
.
//改成中文列名时,可将中文列名放入string[]中,然后循环此数组,将第一行改成相应的中文列名
#endregion
xBook.SaveAs(txtPath.Text, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
myExcel.Visible = true;
}
else
{
System.Windows.Forms.MessageBox.Show("No Data");
}
}
#endregion
#region 把数据文件导出为wps
public void ExportToWps(DataSet ds)
{
if (ds.Tables.Count > 0)
{
eTApp = new ET.Application();
eTApp.Visible = false;
eTWorkBook = eTApp.Workbooks.Open(txtPath.Text, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
eTWorkSheet = (ET.Worksheet)eTWorkBook.Worksheets[1];
#region 改成中文列名
eTWorkBook.ActiveSheet.Cells.set_Item(1, 1, "程序员")
#endregion