导入导出EXL

/// <summary>
    /// 导出公用方法
    /// </summary>
    public class ImportBase
    {
        /// <summary>
        ///  NOPI控件实现导入数据
        /// </summary>
        /// <param name="FilesName">file上传文件ID</param>
        /// <returns>DataTable</returns>
        public static DataTable ImportExcel(HttpPostedFileBase files1)
        {

            //上传和返回(保存到数据库中)的路径
            string uppath = string.Empty;
            string savepath = string.Empty;

            string nameImg = Guid.NewGuid().ToString();

            //记录excel中的所有图片的数据库路径
            List<string> list_Url = new List<string>();

            #region 上传临时文件部分
            //导入文档格式校验
            if (files1.ContentType != "application/vnd.ms-excel")
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("error");
                dt.Rows.Add("error");
                return dt;
            }

            string fileName = files1.FileName;

            //获得上传图片的类型(后缀名)
            string type = fileName.Substring(fileName.LastIndexOf(".") + 1).ToLower();

            HttpPostedFileBase files = files1;
            Stream filedata = files.InputStream;//上传文件的流

            #endregion
            IWorkbook workbook = WorkbookFactory.Create(filedata);
            //HSSFWorkbook hssfWorkBook = new HSSFWorkbook(file);
            IList pictures = workbook.GetAllPictures();
            ISheet sheet = workbook.GetSheetAt(0); //取第一个表
            DataTable table = new DataTable();

            IRow headerRow = sheet.GetRow(0);//第一行为标题行
            int cellCount = headerRow.LastCellNum;//LastCellNum = PhysicalNumberOfCells
            int rowCount = sheet.LastRowNum;//LastRowNum = PhysicalNumberOfRows - 1

            //handling header.
            for (int i = headerRow.FirstCellNum; i < cellCount; i++)
            {
                ICell hs = headerRow.GetCell(i);
                //ColumnDataType[i] = GetCellDataType(hs);
                //CellType dsfa = hs.CellType;
                DataColumn column = new DataColumn(headerRow.GetCell(i).StringCellValue);
                table.Columns.Add(column);
            }

            for (int i = (sheet.FirstRowNum + 1); i <= rowCount; i++)
            {
                IRow row = sheet.GetRow(i);
                DataRow dataRow = table.NewRow();

                if (row != null)
                {
                    for (int j = 0; j < cellCount; j++)
                    {
                        if (row.GetCell(j) != null)
                        {
                            dataRow[j] = row.GetCell(j);
                        }
                        //else
                        //{
                        //    dataRow[j] = list_Url[i - 1];
                        //}
                    }
                }

                table.Rows.Add(dataRow);
            }

            return table;
        }
        /// <summary>
        /// 将Excel导入到DataSet
        /// 返回DataSet
        /// </summary>
        /// <returns></returns>
        public static DataSet ExcelToDataSet(string fileupexcel,HttpPostedFileBase file)
        {
            string strType = System.IO.Path.GetExtension(fileupexcel);
            DataSet ds = new DataSet();
            string filepath = HttpContext.Current.Server.MapPath(@"~/UpExcel/") + Guid.NewGuid().ToString().Trim()+strType;//
            string path= HttpContext.Current.Server.MapPath("~/UpExcel/");

            if (File.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            file.SaveAs(filepath);
            string strCon = string.Empty;
            if (strType == ".xlsx")
            {
                strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath + ";Extended Properties=‘Excel 12.0;IMEX=1‘";
            }
            else if (strType == ".xls")
            {
                strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=‘Excel 8.0;IMEX=1‘";
            }
            OleDbConnection conn = new OleDbConnection(strCon);
            conn.Open();
            DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
            string tblname = "[" + schemaTable.Rows[0][2].ToString().Trim() + "]";
            try
            {
                string sql = "select * from " + tblname;
                OleDbDataAdapter adapter = new OleDbDataAdapter(sql, conn);
                adapter.Fill(ds, tblname);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {

                conn.Close();
                File.Delete(filepath);
            }

            return ds;
        }

    }

  #region 导出
        /// <summary>
        /// 导出
        /// </summary>
        /// <returns></returns>
        public ActionResult ExportExcel()
        {
            GetPubParameter();
            IList<IT_TechnicalInformation> list = new List<IT_TechnicalInformation>();
            if (Request.QueryString["ids"] != null)
            {
                string ids = HttpUtility.UrlDecode(Request.QueryString["ids"]);
                string[] idCollections = ids.TrimEnd(‘,‘).Split(new char[] { ‘,‘ });
                if (idCollections != null)
                {
                    for (int i = 0; i < idCollections.Length; i++)
                    {
                        IT_TechnicalInformation info = new IT_TechnicalInformation();
                        if (!string.IsNullOrEmpty(idCollections[i]))
                        {
                            info = technicalbll.GetModel(idCollections[i]);
                            list.Add(info);
                        }
                    }
                    NPOIExcel(list);
                }
            }

            return null;
        }
        #endregion

        #region 使用NPOI控件实现导出
        private void NPOIExcel(IList<IT_TechnicalInformation> list)
        {
            string path = ConfigurationManager.AppSettings["fileProxy"];
            FileInfo TheFile = new FileInfo(Server.MapPath(path));
            if (!TheFile.Directory.Exists)
            {
                TheFile.Directory.Create();
            }
            MemoryStream ms = new MemoryStream();
            NPOI.HSSF.UserModel.HSSFWorkbook workbook = new NPOI.HSSF.UserModel.HSSFWorkbook();
            NPOI.SS.UserModel.ISheet sheet = workbook.CreateSheet();
            NPOI.SS.UserModel.IRow headerRow = sheet.CreateRow(0);
            NPOI.SS.UserModel.ICell cel2 = headerRow.CreateCell(0);
            headerRow.CreateCell(0).SetCellValue("主题");
            headerRow.CreateCell(1).SetCellValue("产品");
            headerRow.CreateCell(2).SetCellValue("技术");
            headerRow.CreateCell(3).SetCellValue("创建人");
            headerRow.CreateCell(4).SetCellValue("创建时间");

            NPOI.HSSF.UserModel.HSSFCellStyle cs2 = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            NPOI.HSSF.UserModel.HSSFFont font2 = (NPOI.HSSF.UserModel.HSSFFont)workbook.CreateFont();
            font2.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.Bold;
            cs2.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
            cs2.FillForegroundColor = 40;
            cs2.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Top;
            cs2.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
            cs2.SetFont(font2);
            cs2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
            cs2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
            cs2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
            cs2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
            for (int i = 0; i <= 4; i++)
            {
                sheet.SetColumnWidth(i, 100 * 40);
                headerRow.GetCell(i).CellStyle = cs2;
            }
            headerRow.HeightInPoints = 30;

            int rowIndex = 1;
            NPOI.HSSF.UserModel.HSSFPatriarch patriarch = (NPOI.HSSF.UserModel.HSSFPatriarch)sheet.CreateDrawingPatriarch();
            if (list != null && list.Count > 0)
            {
                NPOI.HSSF.UserModel.HSSFCellStyle cs3 = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
                NPOI.HSSF.UserModel.HSSFFont font3 = (NPOI.HSSF.UserModel.HSSFFont)workbook.CreateFont();
                cs3.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Top;
                cs3.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
                for (int i = 0; i < list.Count; i++)
                {
                    IT_TechnicalInformation info = technicalbll.GetModel(list[i].TechnicalInformation_ID);
                    NPOI.SS.UserModel.IRow dataRow = sheet.CreateRow(rowIndex);
                    dataRow.CreateCell(0).SetCellValue(info.TechnicalName);
                    dataRow.CreateCell(1).SetCellValue(info.ProductName);
                    dataRow.CreateCell(2).SetCellValue(info.ResearcherName);
                    dataRow.CreateCell(3).SetCellValue(info.CreateBy);
                    dataRow.CreateCell(4).SetCellValue(info.CreateTime.Value.ToString("yyyy-MM-dd"));

                    for (int j = 0; j <= 4; j++)
                    {
                        dataRow.GetCell(j).CellStyle = cs3;
                    }
                    dataRow.HeightInPoints = 30;
                    rowIndex++;
                }

                workbook.Write(ms);
                ms.Flush();
                ms.Position = 0;
                sheet = null;
                headerRow = null;
                workbook = null;

                string excelname = System.DateTime.Now.ToString().Replace(":", "").Replace("-", "").Replace(" ", "");
                string filePath = Server.MapPath(path + "ReadExcel") + "" + Guid.NewGuid().ToString() + "导出.xls";
                FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
                byte[] data = ms.ToArray();
                fs.Write(data, 0, data.Length);
                fs.Flush();
                fs.Close();
                data = null;
                ms = null;
                fs = null;
                #region 导出到客户端
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                Response.AppendHeader("content-disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode("导出", System.Text.Encoding.UTF8) + ".xls");
                Response.ContentType = "Application/excel";
                Response.WriteFile(filePath);
                Response.End();
                FileInfo f = new FileInfo(filePath);
                f.Delete();
                #endregion
                Response.Write("<script>history.go(-1);</script>");
            }
            else
            {
                Response.Write("<script>alert(‘没有可导出的数据!‘);history.go(-1);</script>");
            }
        }
        #region 导出
        /// <summary>
        /// 导出
        /// </summary>
        /// <returns></returns>
        public ActionResult ExportExcels()
        {
            GetPubParameter();
            IList<IT_InformationPatent> list = new List<IT_InformationPatent>();
            if (Request.QueryString["ids"] != null)
            {
                string ids = HttpUtility.UrlDecode(Request.QueryString["ids"]);
                string[] idCollections = ids.TrimEnd(‘,‘).Split(new char[] { ‘,‘ });
                if (idCollections != null)
                {
                    for (int i = 0; i < idCollections.Length; i++)
                    {
                        IT_InformationPatent info = new IT_InformationPatent();
                        if (!string.IsNullOrEmpty(idCollections[i]))
                        {
                            info = infoPatbll.GetModel(idCollections[i]);
                            list.Add(info);
                        }
                    }
                    NPOIExcels(list);
                }
            }

            return null;
        }
        #endregion
        private void NPOIExcels(IList<IT_InformationPatent> list)
        {
            string path = ConfigurationManager.AppSettings["fileProxy"];
            FileInfo TheFile = new FileInfo(Server.MapPath(path));
            if (!TheFile.Directory.Exists)
            {
                TheFile.Directory.Create();
            }
            MemoryStream ms = new MemoryStream();
            NPOI.HSSF.UserModel.HSSFWorkbook workbook = new NPOI.HSSF.UserModel.HSSFWorkbook();
            NPOI.SS.UserModel.ISheet sheet = workbook.CreateSheet();
            NPOI.SS.UserModel.IRow headerRow = sheet.CreateRow(0);
            NPOI.SS.UserModel.ICell cel2 = headerRow.CreateCell(0);
            headerRow.CreateCell(0).SetCellValue("名称");
            headerRow.CreateCell(1).SetCellValue("申请号");
            headerRow.CreateCell(2).SetCellValue("发明人");
            headerRow.CreateCell(3).SetCellValue("类型");
            headerRow.CreateCell(4).SetCellValue("产品");
            headerRow.CreateCell(5).SetCellValue("技术");
            headerRow.CreateCell(6).SetCellValue("申请日");
            headerRow.CreateCell(7).SetCellValue("摘要");
            headerRow.CreateCell(8).SetCellValue("状态");
            headerRow.CreateCell(9).SetCellValue("日");
            headerRow.CreateCell(10).SetCellValue("号");
            headerRow.CreateCell(11).SetCellValue("申请人");
            headerRow.CreateCell(12).SetCellValue("机构");
            headerRow.CreateCell(13).SetCellValue("等级");
            headerRow.CreateCell(14).SetCellValue("备注");

            NPOI.HSSF.UserModel.HSSFCellStyle cs2 = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
            NPOI.HSSF.UserModel.HSSFFont font2 = (NPOI.HSSF.UserModel.HSSFFont)workbook.CreateFont();
            font2.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.Bold;
            cs2.FillPattern = NPOI.SS.UserModel.FillPattern.SolidForeground;
            cs2.FillForegroundColor = 40;
            cs2.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Top;
            cs2.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
            cs2.SetFont(font2);
            cs2.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
            cs2.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
            cs2.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
            cs2.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
            for (int i = 0; i <= 14; i++)
            {
                sheet.SetColumnWidth(i, 100 * 40);
                headerRow.GetCell(i).CellStyle = cs2;
            }
            headerRow.HeightInPoints = 30;

            int rowIndex = 1;
            NPOI.HSSF.UserModel.HSSFPatriarch patriarch = (NPOI.HSSF.UserModel.HSSFPatriarch)sheet.CreateDrawingPatriarch();
            if (list != null && list.Count > 0)
            {
                NPOI.HSSF.UserModel.HSSFCellStyle cs3 = (NPOI.HSSF.UserModel.HSSFCellStyle)workbook.CreateCellStyle();
                NPOI.HSSF.UserModel.HSSFFont font3 = (NPOI.HSSF.UserModel.HSSFFont)workbook.CreateFont();
                cs3.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Top;
                cs3.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
                for (int i = 0; i < list.Count; i++)
                {
                    NPOI.SS.UserModel.IRow dataRow = sheet.CreateRow(rowIndex);
                    dataRow.CreateCell(0).SetCellValue(list[i].PatentName);
                    dataRow.CreateCell(1).SetCellValue(list[i].AppPatentNO);
                    dataRow.CreateCell(2).SetCellValue(list[i].Inventor);
                    dataRow.CreateCell(3).SetCellValue(list[i].PatentType);
                    dataRow.CreateCell(4).SetCellValue(list[i].ProductName);
                    dataRow.CreateCell(5).SetCellValue(list[i].ResearcherName);
                    dataRow.CreateCell(6).SetCellValue(list[i].ApplicationDate.Value.ToString("yyyy-MM-dd"));
                    dataRow.CreateCell(7).SetCellValue(list[i].Summary);
                    dataRow.CreateCell(8).SetCellValue(list[i].LawState);
                    dataRow.CreateCell(9).SetCellValue(list[i].DulletinData.Value.ToString("yyyy-MM-dd"));
                    dataRow.CreateCell(10).SetCellValue(list[i].DulletinNO);
                    dataRow.CreateCell(11).SetCellValue(list[i].AppPatentUser);
                    dataRow.CreateCell(12).SetCellValue(list[i].Agency);
                    dataRow.CreateCell(13).SetCellValue(list[i].Level);
                    dataRow.CreateCell(14).SetCellValue(list[i].Remark);
                    for (int j = 0; j <= 14; j++)
                    {
                        dataRow.GetCell(j).CellStyle = cs3;
                    }
                    dataRow.HeightInPoints = 30;
                    rowIndex++;
                }

                workbook.Write(ms);
                ms.Flush();
                ms.Position = 0;
                sheet = null;
                headerRow = null;
                workbook = null;

                string excelname = System.DateTime.Now.ToString().Replace(":", "").Replace("-", "").Replace(" ", "");
                string filePath = Server.MapPath(path + "ReadExcel") + "" + Guid.NewGuid().ToString() + "导出.xls";
                FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
                byte[] data = ms.ToArray();
                fs.Write(data, 0, data.Length);
                fs.Flush();
                fs.Close();
                data = null;
                ms = null;
                fs = null;
                #region 导出到客户端
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                Response.AppendHeader("content-disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode("导出", System.Text.Encoding.UTF8) + ".xls");
                Response.ContentType = "Application/excel";
                Response.WriteFile(filePath);
                Response.End();
                FileInfo f = new FileInfo(filePath);
                f.Delete();
                #endregion
                Response.Write("<script>history.go(-1);</script>");
            }
            else
            {
                Response.Write("<script>alert(‘没有可导出的数据!‘);history.go(-1);</script>");
            }
        }
        #endregion
        /// <summary>
        /// 导入方法
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Import()
        {
            HttpPostedFileBase files1 = Request.Files["localImport"];
            DataTable dt = ImportBase.ExcelToDataSet(files1.FileName, files1).Tables[0];
            if (dt.Rows.Count > 0)
            {
                if (dt.Rows[0][0].ToString().Trim() == "error")
                {
                    Response.Write("<script> window.parent.uploadSuccess(‘导入文件错误,请重新上传导入文件!‘);</script>");
                }
                else
                {
                    try
                    {
                        if (dt.Rows.Count > 0)
                        {
                            for (int i = 0; i < dt.Rows.Count; i++)
                            {
                                IT_InformationPatent info = new IT_InformationPatent();
                                info.InformationPatent_ID = Guid.NewGuid().ToString();
                                info.TechnicalID = List;
                                info.AppPatentNO = dt.Rows[i]["申请号"].ToString().Trim();
                                if (string.IsNullOrEmpty(dt.Rows[i]["申请日"].ToString().Trim()))
                                {
                                    info.ApplicationDate = null;
                                }
                                else
                                {
                                    info.ApplicationDate = Convert.ToDateTime(dt.Rows[i]["申请日"].ToString().Trim());
                                }
                                info.PatentName = dt.Rows[i]["名称"].ToString().Trim();
                                info.Summary = dt.Rows[i]["摘要"].ToString().Trim();
                                info.PatentType = dt.Rows[i]["类型"].ToString().Trim();
                                info.LawState = dt.Rows[i]["状态"].ToString().Trim();

                                if (string.IsNullOrEmpty(dt.Rows[i]["日"].ToString().Trim()))
                                {
                                    info.DulletinData = null;
                                }
                                else
                                {
                                    info.DulletinData = Convert.ToDateTime(dt.Rows[i]["授权公告日"].ToString().Trim());
                                }
                                info.DulletinNO = dt.Rows[i]["号"].ToString().Trim();
                                info.AppPatentUser = dt.Rows[i]["申请人"].ToString().Trim();
                                info.Inventor = dt.Rows[i]["发明人"].ToString().Trim();
                                info.Agency = dt.Rows[i]["机构"].ToString().Trim();
                                info.Researchers = dt.Rows[i]["技术"].ToString().Trim();
                                info.Products = dt.Rows[i]["产品"].ToString().Trim();
                                info.Level = dt.Rows[i]["等级"].ToString().Trim();
                                info.Remark = dt.Rows[i]["备注"].ToString().Trim();
                                info.CreateBy = dt.Rows[i]["创建人"].ToString().Trim();
                                if (string.IsNullOrEmpty(dt.Rows[i]["创建时间"].ToString().Trim()))
                                {
                                    info.CreateTime = null;
                                }
                                else
                                {
                                    info.CreateTime = Convert.ToDateTime(dt.Rows[i]["创建时间"].ToString().Trim());
                                }
                                info.UpdateBy = dt.Rows[i]["更新人"].ToString().Trim();
                                if (string.IsNullOrEmpty(dt.Rows[i]["更新时间"].ToString().Trim()))
                                {
                                    info.UpdateTime = null;
                                }
                                else
                                {
                                    info.UpdateTime = Convert.ToDateTime(dt.Rows[i]["更新时间"].ToString().Trim());
                                }
                                informationbll.Add(info);
                                Response.Write("<script> top.uploadSuccess(‘导入数据成功!‘);window.parent.location.reload();</script>");
                            }
                        }
                    }
                    catch (Exception)
                    {
                        Response.Write("<script> window.parent.uploadSuccess(‘导入文件错误,请重新上传导入文件!‘);</script>");
                    }
                }
            }
            else
            {

                Response.Write("<script> window.parent.uploadSuccess(‘导入文件没有数据,请重新上传导入文件!‘);</script>");
            }
            return null;
        }
时间: 2024-08-08 13:38:36

导入导出EXL的相关文章

.net 自己写的操作Excel 导入导出 类(以供大家参考和自己查阅)

由于现在网页很多都关系到Excel 的操作问题,其中数据的导入导出更是频繁,作为一个菜鸟,收集网上零散的知识,自己整合,写了一个Excel导入到GridView ,以及将GridView的数据导出到EXCEL的类方法,以供参考和方便自己以后查阅. 1 #region 引用部分 2 using System; 3 using System.Collections.Generic; 4 using System.Linq; 5 using System.Web; 6 using System.Dat

PL/SQLDeveloper导入导出Oracle数据库方法

前一篇博客介绍了Navicat工具备份Oracle的方法,这篇博客介绍一下使用PL/SQL Developer工具导入导出Oracle数据库的方法. PL/SQL Developer是Oracle数据库用于导入导出数据库的主要工具之一,本文主要介绍利用PL/SQL导入导出Oracle数据库的过程. 1.Oracle数据库导出步骤 1.1 Tools→Export User Objects...选项,导出.sql文件. 说明:此步骤导出的是建表语句(包括存储结构). 1.2 Tools→Expor

Eclipse调试程序及项目的导入导出

Eclipse调试程序 调试概述: ①   调试就是测试程序的方法,主要的目的就是解决程序的逻辑问题,流程是:发现问题.修改问题.正确执行; ②   以前我们可以使用System.out.println()方法来查看我们程序中的问题; ③   现在我们可以使用Eclipse开发工具帮我们进行调试: Eclipse为程序员提供了设置断点的功能来达到单步调试程序的能力; 调试步骤: ①   初步判断程序出错的位置; ②   给指定的程序设置断点(可以设置多个); ③   进入调试视图让程序在断点位置

Excel导入导出的业务进化场景及组件化的设计方案(转)

1:前言 看过我文章的网友们都知道,通常前言都是我用来打酱油扯点闲情的. 自从写了上面一篇文章之后,领导就找我谈话了,怕我有什么想不开. 所以上一篇的(下)篇,目前先不出来了,哪天我异地二次回忆的时候,再分享分享. 话说最近外面IT行情飞涨还咋的,人都飞哪去了呢,听说各地的军情都进入紧急状态了. 回归下正题,今天就抽点时间,写写技术文,和大伙分享一下近年在框架设计上的取的一些技术成果. 2:项目背景 在针对运营商(移动.联通.电信.铁塔)的信息类的系统中,由于相关的从业人员习惯于Excel的办公

自用Postgres 数据库的导入导出脚本

工作中时常给开发和测试导入导出一些测试的数据库,于是写了一个脚本方便操作. 公司目前使用的是postgres9.3数据库. #!/bin/bash #定义一些变量和操作命令 DBS="db1 db2 db3 db4" EXPDB_CMD=/usr/pgsql-9.3/bin/pg_dump DBCMD=/usr/pgsql-9.3/bin/psql DBUSER=postgres DBSVR=mydbhost1 #导出数据库 function exportdb() {   read -

excel的导入导出的实现

1.创建Book类,并编写set方法和get方法 1 package com.bean; 2 3 public class Book { 4 private int id; 5 private String name; 6 private String type; 7 // public int a; 8 9 public String getType() { 10 System.out.println("调用了类型方法"); 11 return type; 12 } 13 14 pu

利用反射实现通用的excel导入导出

如果一个项目中存在多种信息的导入导出,为了简化代码,就需要用反射实现通用的excel导入导出 实例代码如下: 1.创建一个 Book类,并编写set和get方法 1 package com.bean; 2 3 public class Book { 4 private int id; 5 private String name; 6 private String type; 7 // public int a; 8 9 public String getType() { 10 System.ou

java项目中Excel文件的导入导出

1 package poi.excel; 2 3 import java.io.IOException; 4 import java.io.InputStream; 5 import java.io.OutputStream; 6 import java.lang.reflect.Field; 7 import java.lang.reflect.Method; 8 import java.util.ArrayList; 9 import java.util.List; 10 11 import

PHP 和 JS 导入导出csv表格(上)

CSV简介 在开发后台管理系统的时候,几乎无可避免的会遇到需要导入导出Excel表格的需求.csv也是表格的一种,其中文名为"逗号分隔符文件".在Excel中打开如下图左边所示,在记事本打开如下图右边所示: 再看包含特殊字符的表格 与xls或xlsx 表格相类似,CSV文件也是用来表示二维表格.而不同的是: 1.CSV是一种纯文本文件,任何编辑器都能打开并读取它:xls(x)是专用的二进制文件,要用表格软件才能正常打开,否则乱码: 2.CSV的体积很小,比如上面的表格内容,csv只有几