//将Excel表格中某一sheet中内容放于dataGrid中显示示例:
/*
string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = f://表.xls;Extended Properties=Excel 8.0";
OleDbConnection myConn = new OleDbConnection(strCon);
string strCom = " SELECT * FROM [表$] ";
myConn.Open();
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
DataSet myDataSet;
myDataSet = new DataSet();
myCommand.Fill(myDataSet, "[表$]");
myConn.Close();
this.dataGridView1.DataSource = myDataSet.Tables[0];
*/
//新建一个只含有一个表单的Excel文件,并对其内单元格进行操作示例:
/*
Microsoft.Office.Interop.Excel.Application newXls = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook obj = newXls.Application.Workbooks.Add(true);
newXls.Cells[1, 2] = "hei,chrovan!";
// newXls.Workbooks.Add(@"f:/表.xls");
newXls.Visible = false;
obj.SaveAs(@"f:/xx.xls", Microsoft.Office.Interop.Excel.XlFileFormat.xlExcel9795, null, null, false, false, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, null, null, null, null,null);
newXls.Application.Quit();
*/
//获得所有的sheet
/*
public string GetExcelSheetName(string path1)
{
string tableName = null;
if (File.Exists(path1))
{
using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet."+
"OLEDB.4.0;Extended Properties=/"Excel 8.0/";Data Source=" + path1))
{
conn.Open();
DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
for(int i=0;i<dt.Rows.Count;i++)
{
tableName+=dt.Rows[i][2].ToString().Trim()+";";
}
}
}
return tableName;
}
*/

2741

被折叠的 条评论
为什么被折叠?



