码迷,mamicode.com
首页 > Windows程序 > 详细

C#利用最新版的WPS实现导入导出

时间:2015-07-09 00:54:43      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:

微软的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引用如下图:技术分享


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;
            Response.Write(data);
        }
    }
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

C#利用最新版的WPS实现导入导出

标签:

原文地址:http://blog.csdn.net/hutao1101175783/article/details/46810231

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!