首页 > 代码库 > C#利用最新版的WPS实现导入导出
C#利用最新版的WPS实现导入导出
微软的EXCEl操作相信大家也知道,不方便,安装包太大,而且表格的数据量也只有6000多(是6000多还是60000多我就忘记了),在导出导入大量数据的就没办法,而wsp表格则实现了百万数据的容量,而且安装包也小,操作更方便。下面利用最wps2015实现了一个简单的导入到出,参考http://blog.163.com/felex_cheng@126/blog/static/410470052013818325357/文章,也可也参考一下wsp二次开发文档http://www.wps.cn/wpsapi/funcapilist/page-1.htm,相应的dll引用如下图:
本程序要引用etapi.all
[csharp] view plain copy
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using Excel;
- namespace WebApplication1
- {
- public partial class WebForm1 : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- Excel.Application appli = new Application();
- /*wsp excel导出*/
- /*Excel._Workbook wk = appli.Workbooks.Add(Type.Missing);
- Excel.Worksheet sheet = wk.ActiveSheet;
- sheet.Cells[1, 1] = "WPS表格测试";
- wk.SaveAs(Server.MapPath("/2.xls"), Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
- wk.Close(Type.Missing, Type.Missing, Type.Missing);
- System.Runtime.InteropServices.Marshal.ReleaseComObject(wk);
- System.Runtime.InteropServices.Marshal.ReleaseComObject(appli);*/
- /*wps excel导入*/
- Excel._Workbook wk = appli.Workbooks.Open(Server.MapPath("/2.xls"));
- Excel.Worksheet sheet = wk.Worksheets.get_Item(1);
- Excel.Range range = sheet.UsedRange;
- string data = ((Excel.Range)range.get_Item(1, 1)).Text;
- int rowCount = range.Rows.Count;
- int columCount = range.Columns.Count;
- for (int j = 1; j <= rowCount; j++)
- {
- string info = "";
- for (int i = 1; i <= columCount; i++)
- {
- info += " " + ((Excel.Range)range.get_Item(j)).Cells[j, i].Text;
- }
- Response.Write(info + "
- ");
- }
- }
- }
- }
导入效果:
C#利用最新版的WPS实现导入导出
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。