同上 希望给点代码啊
解决方案 »
- 想不出来,有点麻烦了。
- 请问asp.net如何验证域用户和密码
- 保存object到数据库
- 关于网站简体转换成繁体后链接也跟着转换成繁体而出错的问题
- 如何使一维列表变成二维列表的形式绑定到下拉框中呢?
- 关于.net下email的几个问题?
- 请教:无法识别的属性“loginURL”。
- MVC3 在过滤器中使用cookie为何无法存入请求中
- 日期语法错误,应怎样解决 ><
- 使用VS2017创建支持DOCKER的ASP.NET CORE项目后,项目结构中不包含docker compose 项目
- GridView如何编程隐藏EditItemTemplate中的Calendar控件?
- 什么去除html代码,包括有图像的
public static string GetExcel(string excelname)
{
try
{
object Nothing = System.Reflection.Missing.Value;
string toname = excelname + ".txt";
/*Excel.ApplicationClass getexc = new Excel.ApplicationClass();
Type ExcelType = getexc.GetType();
Excel.Workbook Exceltemp = getexc.WorkbookActivate;
Type Exceltype = Exceltemp.GetType();
Excel.Workbook exc = (Excel.Workbook)Exceltype.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, doctemp, new Object[] { excelname, true, true });
Type excType = exc.GetType();
excType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { toname, .WdSaveFormat.wdFormatText });
ExcelType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, getwor, null);*/
Excel.Application exc = new Excel.Application();
exc.Workbooks.Open(excelname, true, 2, 5, Nothing, Nothing, true, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing);
exc.ActiveWorkbook.SaveAs(toname, Excel.XlFileFormat.xlUnicodeText, Nothing, Nothing, Nothing, Nothing, Excel.XlSaveAsAccessMode.xlExclusive, Nothing, Nothing, Nothing, Nothing, Nothing);
exc.ActiveWorkbook.Close(false, toname, false);
//exc.ActiveWindow.Close(false, toname, false);
//exc.Application.Quit();
exc.Workbooks.Close();
exc.Quit();
exc = null;
GC.Collect();
return creatlogs.GetTxt(toname);
}
catch(Exception e)
{
creatlogs.Eventlog(excelname.ToString(), e.Message + "#excel文本读取失败");
return "";
}
}
public static DataTable ImportExcel(string fileName)
{
string xlsDriver = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;";
OleDbConnection cn = new OleDbConnection( string.Format(xlsDriver, fileName) );
cn.Open();
try
{
DataTable schema = cn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,new object[] {null, null, null, "TABLE"});
//下面取得第一个表名
string tableName = schema.Rows[0]["TABLE_NAME"].ToString(); OleDbDataAdapter da = new OleDbDataAdapter("select * from [" + tableName + "]",cn);
DataSet ds = new DataSet();
da.Fill(ds); da.Dispose();
cn.Dispose(); return ds.Tables[0];
}
catch(Exception ex)
{
MessageBox.Show("对不起,数据导入出错!\\n" + ex.Message,"出错",MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
finally
{
if (cn != null) cn.Dispose();
}
}
http://blog.csdn.net/blog51/archive/2007/08/28/1761493.aspx