• 首页
  • 脚本说明
    • 脚本介绍
    • 第一个助码脚本程序
    • 常用类型哈希表
    • 常用类型哈希表集合
    • 常用类型字符串
    • 基本数字类型
    • 数据库操作
    • Excel操作
    • 模拟http请求
  • 通用基类
    • ZmHash
    • StringUtil
    • FlowDefine
    • FlowDefineLine
    • ZmHashList
    • FlowDefineStep
    • JobBase
    • IModelData
    • FrameController
    • FrameDao
    • FlowBase
    • ZmActiveRequest
    • ZmQueryConditionList
    • ZmQueryTable
    • ZmStr2StrHash
    • ZmReturnMsg
    • MainModel
    • ViewModelBase
    • ZmConfig
    • ZmListBase
    • ZmList
    • MapperBase
    • ZmServiceBase
    • ZmController
    • IZmServiceBase
    • ActionModelView
    • ZmPageData
    • ReturnMessage
    • ReturnData
    • SearchData
    • FrameFlow
  • 数据库操作
    • BaseProvider
    • ZmSqlParam
    • ZmSqlParamList
  • 工具函数
    • JsonHelper
    • HttpUtil
    • RandomUtil
    • VerificationCode
    • CryptUtil
    • ZmQRCode
    • SmsSenderHelper
    • ZmUtil
    • ExcelUtil
  • 首页
  • 脚本说明
    • 脚本介绍
    • 第一个助码脚本程序
    • 常用类型哈希表
    • 常用类型哈希表集合
    • 常用类型字符串
    • 基本数字类型
    • 数据库操作
    • Excel操作
    • 模拟http请求
  • 通用基类
    • ZmHash
    • StringUtil
    • FlowDefine
    • FlowDefineLine
    • ZmHashList
    • FlowDefineStep
    • JobBase
    • IModelData
    • FrameController
    • FrameDao
    • FlowBase
    • ZmActiveRequest
    • ZmQueryConditionList
    • ZmQueryTable
    • ZmStr2StrHash
    • ZmReturnMsg
    • MainModel
    • ViewModelBase
    • ZmConfig
    • ZmListBase
    • ZmList
    • MapperBase
    • ZmServiceBase
    • ZmController
    • IZmServiceBase
    • ActionModelView
    • ZmPageData
    • ReturnMessage
    • ReturnData
    • SearchData
    • FrameFlow
  • 数据库操作
    • BaseProvider
    • ZmSqlParam
    • ZmSqlParamList
  • 工具函数
    • JsonHelper
    • HttpUtil
    • RandomUtil
    • VerificationCode
    • CryptUtil
    • ZmQRCode
    • SmsSenderHelper
    • ZmUtil
    • ExcelUtil
Excel操作
说明 Excel操作(ExcelUtil) ExcelUtil 操作Excel工具类 常用方法 AddCellFontColor 设置单元格样式的字体颜色 AddCellFontWeight 设置单元格样式的字体加粗 AddCellForegroundColor 设置单元格样式的前景色 AddCellFontSize 设置单元格样式的字体大小 AddCellHorizontalAlignmentRight 设置单元格样式的水平对齐属性为靠右 AddCellHorizontalAlignmentCenter 设置单元格样式的水平对齐属性为居中 AddCellHorizontalAlignmentLeft 设置单元格样式的水平对齐属性为靠左 AddCellVerticalAlignmentBottom 设置单元格样式的垂直对齐属性为靠下 AddCellVerticalAlignmentCenter 设置单元格样式的垂直对齐属性为居中 AddCellVerticalAlignmentTop 设置单元格样式的垂直对齐属性为靠上 AddCellBorderLeftThin 设置单元格样式的左边框为thin样式 AddCellBorderBottomThin 设置单元格样式的下边框为thin样式 AddCellBorderTopThin 设置单元格样式的上边框为thin样式 AddCellBorderRightThin 设置单元格样式的右边框为thin样式 AddCellsSingleStyle 往配置对象中添加单元格样式 AddRowHeightStyle 导出配置中添加行高 AddColWidthStyle 导出配置中添加列宽 AddColDataTypeBool 导出配置中 设置列的数据类型 为布尔型(bool) AddColDataTypeDate 导出配置中 设置列的数据类型 为日期型(date) AddColDataTypeString 导出配置中 设置列的数据类型 为字符串(string) AddColDataTypeNumeric 导出配置中 设置列的数据类型 为数值型(numeric) AddBodyCellStyle 导出配置中添加表格内容样式 AddHeadCellStyle 导出配置中添加表格头样式 ImportFromExcelRequest 从http请求文件流中获取文件,并导入为哈希对象 ImportFromExcelFile 将excel中的数据导入为哈希对象 ExportSingleSheetHeadBodyToExcelResponse 导出单个sheet到http响应流 单个sheet数据分为表格头和表格内容的形式 ExportSingleSheetHeadBodyToExcelFile 导出单个sheet为Excel文件 单个sheet数据分为表格头和表格内容的形式 ExportSingleSheetToExcelResponse 导出单个sheet到http响应流 ExportSingleSheetToExcelFile 导出单个sheet为Excel文件 ExportMutiSheetToExcelResponse 导出多个sheet为http响应流 ExportMutiSheetToExcelFile 导出多个sheet为Excel文件 示例 ZmScript //Excel操作测试 /** * 测试添加头部单元格样式 * * @param cell 头部单元格 */ private void TestAddHeadCell(ZmHash cell) { //设置字体 ExcelUtil.AddCellFontSize(cell, 24); //设置加粗 ExcelUtil.AddCellFontWeight(cell, true); //字体颜色 ExcelUtil.AddCellFontColor(cell, "FF0000"); //单元格前景色 ExcelUtil.AddCellForegroundColor(cell, "00FF00"); //设置垂直靠上 ExcelUtil.AddCellVerticalAlignmentTop(cell); //水平靠右 ExcelUtil.AddCellHorizontalAlignmentRight(cell); //设置上下左右的边框 为thin样式 ExcelUtil.AddCellBorderRightThin(cell); ExcelUtil.AddCellBorderLeftThin(cell); ExcelUtil.AddCellBorderTopThin(cell); ExcelUtil.AddCellBorderBottomThin(cell); } /** * excel导出 * */ @RequestMapping("exportExcel") @ResponseBody public void exportExcel() { ZmActiveRequest zmRequest = base.getActiveRequest(); //excel头 ZmHash strHash = new ZmHash(); strHash.Add("name", "姓名"); strHash.Add("age", "年龄"); //excel内容 ZmHashList dataList = new ZmHashList(); ZmHash hash = new ZmHash(); hash.Add("name", "zhangsan"); hash.Add("age", 18); dataList.Add(hash); hash = new ZmHash(); hash.Add("name", "lisi"); hash.Add("age", 32); dataList.Add(hash); //excel文件名称 string fileName = "testsheet.xlsx"; //导出参数 ZmHash configs = new ZmHash(); //头部单元格样式 ZmHash headCell = new ZmHash(); this.TestAddHeadCell(headCell); //设置单元格样式 ExcelUtil.AddBodyCellStyle(configs, headCell); //行高 ExcelUtil.AddRowHeightStyle(configs, 1, 100); ExcelUtil.AddRowHeightStyle(configs, 2, 100); //设置列宽 ExcelUtil.AddColWidthStyle(configs, "name", 100); //设置列宽 ExcelUtil.AddColWidthStyle(configs, "age", 100); //单个sheet的内容导出到http响应流内 ExcelUtil.ExportSingleSheetHeadBodyToExcelResponse(strHash, dataList, "testsheet", configs, fileName, zmRequest); } /** * excel导入 * */ @RequestMapping("importExcel") @ResponseBody public ZmHash importExcel() { ZmActiveRequest zmRequest = base.getActiveRequest(); //从http请求流中导入Excel ZmReturnMsg returnMsg = ExcelUtil.ImportFromExcelRequest(zmRequest); //会包含一个sheetList字段,内容为导入的excel列表 returnMsg.Add("Result", true); returnMsg.Add("Message", returnMsg.MsgContent); returnMsg.Add("SNO", returnMsg.OtherData); return returnMsg; } Excel的基本操作 Excel 文件的导入 Excel 文件的导出
上一篇:数据库操作
下一篇:模拟http请求
联系电话:17321408562 上海洽发信息科技有限公司 张经理 2022 上海洽发 沪ICP备16029095号-6