Jfinal可以很方便的ajax导出excel文件件吗?renderFile

查看: 9646|回复: 0
JFinal导入EXCEL工具
使用方法1 上传文件到服务器目录2 客户端传回上传文件名称,调用PoiExt.ReadExcel(上传的文件名,插入SQL语句,读取的列数)
注意上传的文件名为全路径3 执行返回一个MAP,返回执行的成功记录数,失败记录数,总记录数使用示例public void impdata() {
if (StrKit.isBlank(getPara("filename"))) {
renderJson(false);
String filename = PathKit.getWebRootPath() + "/"
+ getPara("filename");
filename = filename.replaceAll("\\\\", "/");
Map map = PoiExt
.ReadExcel(filename,"insert into cms_link (lnkIndex,lnkTitle,lnkImg,lnkUrl) values(?,?,?,?)",4);
renderJson(map);
import java.io.FileInputSimport java.io.IOEimport java.util.HashMimport java.util.Mimport org.apache.poi.hssf.usermodel.HSSFCimport org.apache.poi.hssf.usermodel.HSSFRimport org.apache.poi.hssf.usermodel.HSSFSimport org.apache.poi.hssf.usermodel.HSSFWimport com.jfinal.plugin.activerecord.Db;public class PoiExt { public static Map&String, Object& ReadExcel(String filename, String sql,
int ColCount) {
Map&String, Object& map =
@SuppressWarnings(&resource&)
HSSFWorkbook wookbook = new HSSFWorkbook(new FileInputStream(
filename));
HSSFSheet sheet = wookbook.getSheet(&Sheet1&);
int rows = sheet.getPhysicalNumberOfRows();
Object[][] paras = new Object[rows][ColCount];
for (int i = 1; i & i++) {
HSSFRow row = sheet.getRow(i);
if (row != null) {
int cells = row.getPhysicalNumberOfCells();
for (int j = 0; j & j++) {
HSSFCell cell = row.getCell(j);
if (cell != null) {
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_FORMULA:
case HSSFCell.CELL_TYPE_NUMERIC:
paras[i][j] = cell.getNumericCellValue();
case HSSFCell.CELL_TYPE_STRING:
paras[i][j] = cell.getStringCellValue();
paras[i][j] =
int[] ret = Db.batch(sql, paras, 100);
int s = 0, l = 0;
for (int i = 0; i & ret. i++)
if (ret[i] == 1)
map = new HashMap&String, Object&();
map.put(&success&, s);
map.put(&lost&, l);
map.put(&count&, ret.length);
wookbook =
} catch (IOException e) {
e.printStackTrace();
}}复制代码
上一篇:下一篇:神语熙很懒,签名啥也没写
回答了问题:
引用来自“孤独的3”的答案 源码中的,看下吧! 谢谢,原来多加了个/可以了。 renderFile("/home/Public/DataFile/WIP.xls");
请问,jfinal可以导出excel文件吗?有没有集成这个功能,好比renderJson一样方便,本来打算用流导出,不想在服务端生成excel文件,暂时未找到相应的处理办法,决定先在服务端生成excel文件,在用jfinal提供下载。...
对回帖发表评论
依然是404==
String path = PathKit.getWebRootPath() + File.separator + "home" + File.separator + "Public" + File.separator
+ "DateFile" + File.separator + "WIP.xls";
renderFile(new File(path)); 别谢我,代码都给...
对回帖发表评论
我就是renderFile过不去
自己用poi就可以生成excel,或者用jfinal-ext。然后renderFile就可以下载了
对回帖发表评论
这个也太麻烦了吧,就算用response也方便啊,求简单的办法。
http://www.oschina.net/p/jfinal-ext
不要问我是谁,请叫我雷锋!
在讨论区提问:
请问,jfinal可以导出excel文件吗?有没有集成这个功能,好比renderJson一样方便,本来打算用流导出,不想在服务端生成excel文件,暂时未找到相应的处理办法,决定先在服务端生成excel文件,在用jfinal提供下载。...
对回帖发表评论
是oracle查出数据时的表字段被配置文件中的arp.setContainerFactory(new CaseInsensitiveContainerFactory());这一段给转换成大写了,去掉就好了。而我直接renderJson的是查出来的list数据,jfinal并没有对json转...
jfinal 并未在 json 转换时做大小写转换,调试一下转换在何时发生的
对回帖发表评论
回复 @JohnsonZ : arp.setContainerFactory(new CaseInsensitiveContainerFactory()); 我把配置文件里面的这个去掉就可以了
引用来自“JFinal”的答案
jfinal 并未在 json 转换时做大小写转换,调试一下转换在何时发生的 谢谢,可以了。
发表评论:
引用来自“赵占涛”的评论 引用来自“撒旦他舅爷”的评论 eclipse 才是王道myeclipse才是王道myeclipse才是王道
今天看到@sir说myeclipse2014发布了,就下了一个,发现可以定制主题了,我是个极度扁平化主义者,实在受不了eclipse那种风格,然后就制作了一个扁平风格的主题,各个客官请慢用,以后我再试着制作一个vs2013风格的...
回答了问题:
引用来自“JFinal”的答案
jfinal 并未在 json 转换时做大小写转换,调试一下转换在何时发生的 谢谢,可以了。
用renderJSON输出,为啥我写的是小写自动给我转成了大写呢? Record rc=new Record();
rc.set("total", pageList.getTotalRow());
rc.set("rows", pageList.getList());
renderJson(rc); 输出之后我的total和row...
在讨论区提问:
用renderJSON输出,为啥我写的是小写自动给我转成了大写呢? Record rc=new Record();
rc.set("total", pageList.getTotalRow());
rc.set("rows", pageList.getList());
renderJson(rc); 输出之后我的total和row...
还可以输入5字
共 9 张,还能上传 9 张
[选择编程语言]
Apple Swift
Objective-C
JavaScript
Delphi/Pascal
Flash/ActionScript/Flex
WPF/SilverLight
Shell/批处理
设置备注名:
用户尚未登录,点击登录JFinal 是基于 Java 语言的极速 WEB + ORM 框架,其核心设计目标是开发迅速、代码量少、学习简单、功能强大、轻量级、易扩展、Restful。在拥有Java语言所有优势的同时再拥有ruby、python、php等动态语言的
JFinal Weixin 是基于 JFinal 的微信公众号极速开发 SDK,只需浏览 Demo 代码即可进行极速开发,自 JFinal Weixin 1.2 版本开始已添加对多公众号支持。1、WeixinConfig配置详情请见:JF
JPress,一个wordpress的java代替版本,使用JFinal开发。支持类似wordpress的几乎所有功能,比如:模板,插件等。同时在模板上,JPress提出了“模板即模型”的概念,方便模板制作人灵活制作业务模型,移除了wid
JFinal IDE是一个极速创建JFinal开发环境的Eclipse平台插件。小木学堂提供JFinal教程和支持。JFinal开发的微信小程序社区俱乐部http://www.wxappclub.com&
此项目是基于Jfianl_weixin开发的开源项目项目运行截图
模仿的Spring中的消息事件:详解Spring事件驱动模代码简单无任何第三方依赖,具体使用如下:
一、说明JFinal框架结合JFinal3.0 template、jsp、beetl、freemarker模版的js、css在线合并压缩插件!结合CDN使用效果更佳哦!二、依赖&
首创JFinal快速开发平台,降低70%开发成本。快速搞定各类管理系统,赶紧用EOVA给自己加薪吧!Eova能快速实现啥效果呐?&
朋也社区是用Java语言编写的社区(论坛)系统.
微服务分布式框架
我在一个项目中需要上传覆盖原文件,jFinal本身是自动添加1.。。n的,我在上传时做了如下修改。public void upload() { Users user = getSessionAttr("user");
PropKit : 读取properties文件的信息。PathKit: 读取项目路径名。StrKit: 主要是判断字符串的操作。
前两天我的博客网站二当家的先被DDoS,然后又被恶意举报到腾讯安全管家,被屏蔽为不安全的网站了,因为用的是阿里云Centos7,于是提交了一个工单问售后妹子,怎么才可以解除拉白,她说之前遇到类似的事件,一般都是把网站配制为htttps用S
https最关键就是比http更安全,但是https相对http访问速度较慢一些,但是拿现在的浏览器来说,比如chrome,如果不是https的,那么会一直显示不安全的提示,所以要求比较严格的网站,能用h
List&User& user = User.dao.find("select * from emp where empname='"+username+"' and emppassword = '"+userpassword
项目里面一定会有很多的action,每一个都需要验证参数的合法性,这是个很繁琐的工作,jfinal自带的拦截器功能用着还是觉得麻烦;参考hibernate-validator等现有的框架写了点东西,自我感觉美美的,特地来晒一晒(内容挺长,
jfianl怎么更新缓存
我的项目中,将用户登录信息用session保存,并将sessionId保存到用户表中。现在需要实现踢用户线下的功能。问题的关键是,如何通过这个sessionId获取到session进而销毁它?求大神指教!
13:53:53[ERROR]-[Thread: main]-[com.alibaba.druid.pool.DruidDataSource.init()]: init datasource error, url:
gernerator.addExcludedTable可以来选择去除某些表不去做生成 有办法可以指定只有那些表帮我做生成吗,因为我们现在有个数据库是几个项目公用的。 有些表不在我现在这个
需求有点复杂,一开始项目只要支持get和post的x-www-form-urlencode就可以了,但到中期发现还需要application/json方式,前端用的vue,所以后端的接口都是高度集成的(就10个左右接口)。想了一些办法,但
我在model定义中加了一个字段,public class Node extends BaseNode&Node& { public static final Node
今天特别奇怪,之前从来都没出现过这个问题,今天在一张新表(4个varchar的字段)执行时,时不时(差不多每4次就会出现1次的概率)就会出现,返回成功但是数据库里面没有记录的情况,再
我想在Action里面返回403错误,用了如下代码try{ ((HttpServletResponse)this.getRequest()).sendError(403, "权限不够");
我在给前端返回数据的时候,Date类型的数据变成了{"date":20,"hours":23,"seconds":19,"month":2,"nanos":0,"timez
听说JFinal-java8支持形参注入。这具体是怎么使用的?还有就是有关于JFinal-java8的说明吗?
#define select(table,columnNames) select #for(columnName : columnNames) #(for.index & 0?jfinal导入、导出excl
时间: 16:41:49
&&&& 阅读:995
&&&& 评论:
&&&& 收藏:0
标签:@SuppressWarnings("deprecation")public void exportStudent(){
String fileName="考场信息表"+DateKit.getCurrentDateTime("yyyyMMddhhmmss")+".xls";
String path=getRequest().getRealPath("\\")+"upload\\excel\\"+fileN
/*File desktopDir = FileSystemView.getFileSystemView().getHomeDirectory();
String desktopPath = desktopDir.getAbsolutePath();*/
System.out.println(path);
File file=new File(path);
HSSFWorkbook wb = new HSSFWorkbook();
//---&创建了一个excel文件
HSSFSheet sheet = wb.createSheet("考场信息表");
//---&创建了一个工作簿
HSSFDataFormat format= wb.createDataFormat();
//---&单元格内容格式
sheet.setColumnWidth((short)3, 20* 256);
//---》设置单元格宽度,因为一个单元格宽度定了那么下面多有的单元格高度都确定了所以这个方法是sheet的
sheet.setColumnWidth((short)4, 40* 256);
//---&第一个参数是指哪个单元格,第二个参数是单元格的宽度
sheet.setDefaultRowHeight((short)150);
// ----&有得时候你想设置统一单元格的高度,就用这个方法
sheet.setColumnWidth((short)0,
sheet.setColumnWidth((short)1,
sheet.setColumnWidth((short)2,
sheet.setColumnWidth((short)5,
sheet.setColumnWidth((short)6,
sheet.setColumnWidth((short)7,
sheet.setColumnWidth((short)8,
sheet.setColumnWidth((short)9,
sheet.setColumnWidth((short)10,
sheet.setColumnWidth((short)11,
sheet.setColumnWidth((short)12, 20* 256);
sheet.setColumnWidth((short)13, 20* 256);
HSSFCellStyle style = wb.createCellStyle(); // 样式对象
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);// 垂直
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);// 水平
//设置标题字体格式
HSSFFont font = wb.createFont();
//设置字体样式
font.setFontHeightInPoints((short)12);
//---&设置字体大小
font.setFontName("Courier New");
//---》设置字体,是什么类型例如:宋体
font.setItalic(false);
//---&设置是否是加粗
style.setFont(font);
//---&将字体格式加入到style中
//style.setFillForegroundColor(IndexedColors.DARK_YELLOW.getIndex());
// style.setFillPattern("YELLOW");//设置单元格颜色
style.setWrapText(false);
//设置是否能够换行,能够换行为true
//表格第三行
HSSFRow row4 = sheet.createRow(0);
row4.setHeightInPoints((short)25);
HSSFCell cell4_1 = row4.createCell((short)0);
cell4_1.setCellStyle(style);
cell4_1.setCellValue("场次");
HSSFCell cell4_2 = row4.createCell((short)1);
cell4_2.setCellStyle(style);
cell4_2.setCellValue("地市");
HSSFCell cell4_3 = row4.createCell((short)2);
cell4_3.setCellStyle(style);
cell4_3.setCellValue("学校");
HSSFCell cell4_4 = row4.createCell((short)3);
cell4_4.setCellStyle(style);
cell4_4.setCellValue("学生姓名");
HSSFCell cell4_5 = row4.createCell((short)4);
cell4_5.setCellStyle(style);
cell4_5.setCellValue("公位号");
HSSFCell cell4_6 = row4.createCell((short)5);
cell4_6.setCellStyle(style);
cell4_6.setCellValue("代号");
Long competitionId = getParaToLong("competitionId");
Qb qb = new Qb("select a.xsId,a.code,a.userCode,b.xm,c.name,d.city,d.xxmc
FROM CttParticipant a left join CttXS b
on a.xsId = b.id left join CttRonda c
on a.rondaId=c.id left join CttXX d on b.xxId=d.id WHERE a.competitionId=?
",competitionId);
if (StrKit.isNotEmpty(getPara("XsName"))) {
qb.append(" and b.xm like ?", Qb.wrapLike(getPara("XsName")));
if (StrKit.isNotEmpty(getPara("city"))) {
qb.append(" and d.city like ?", Qb.wrapLike(getPara("city")));
if (StrKit.isNotEmpty(getPara("xxName"))) {
qb.append(" and d.xxmc like ?", Qb.wrapLike(getPara("xxName")));
if (StrKit.isNotEmpty(getPara("userCode"))) {
qb.append(" and a.userCode like ?", Qb.wrapLike(getPara("userCode")));
qb.append(getOrderBy("c.name,a.code"));
List&Record& list = Db.find(qb);
int j = 0;
for (Record record : list) {
HSSFRow rowN = sheet.createRow(1+j);
rowN.setHeightInPoints((short)25);
HSSFCell cell_1 = rowN.createCell((short)0);
cell_1.setCellStyle(style);
if(StrKit.isNotEmpty(record.getStr("name"))){
cell_1.setCellValue(record.getStr("name"));
cell_1.setCellValue("");
HSSFCell cell_2 = rowN.createCell((short)1);
cell_2.setCellStyle(style);
if(StrKit.isNotEmpty(record.getStr("city"))){
cell_2.setCellValue(record.getStr("city"));
cell_2.setCellValue("");
HSSFCell cell_3 = rowN.createCell((short)2);
cell_3.setCellStyle(style);
if(StrKit.isNotEmpty(record.getStr("xxmc"))){
cell_3.setCellValue(record.getStr("xxmc"));
cell_3.setCellValue("");
HSSFCell cell_4 = rowN.createCell((short)3);
cell_4.setCellStyle(style);
if(StrKit.isNotEmpty(record.getStr("xm"))){
cell_4.setCellValue(record.getStr("xm"));
cell_4.setCellValue("");
HSSFCell cell_5 = rowN.createCell((short)4);
cell_5.setCellStyle(style);
if(StrKit.isNotEmpty(record.getStr("code"))){
cell_5.setCellValue(record.getStr("code"));
cell_5.setCellValue("");
HSSFCell cell_6 = rowN.createCell((short)5);
cell_6.setCellStyle(style);
if(StrKit.isNotEmpty(record.getStr("userCode"))){
cell_6.setCellValue(record.getStr("userCode"));
cell_6.setCellValue("");
}catch(Exception e){
e.printStackTrace();
FileOutputStream fileOut =
fileOut = new FileOutputStream(file);
wb.write(fileOut);
renderEasyUISuccess(fileName);
System.out.println(fileName);
}catch(Exception e){
e.printStackTrace();
renderEasyUISuccess("导出失败!");
if(fileOut != null){
fileOut.close();
} catch (IOException e) {
e.printStackTrace();
-----------------------------------------------
public void toLead() throws Exception{
UploadFile file = getFile("file");
File tempXlsFile = file.getFile();
// 从excel中读取文件
Long comId = getParaToLong("comId");
String xmlPath = PathKit.getWebRootPath() + "/zjvexml/gwh.xml";
List&?& list = EasyXls.xls2List(xmlPath, tempXlsFile);
for (Object object : list) {
Map&String, Object& map = (Map&String, Object&)
Record re = Db.findFirst("SELECT p.id pid ,s.xm ,x.xxmc from CttParticipant p LEFT JOIN cttxs s on p.xsId=s.id LEFT JOIN CttXX x on s.xxId =x.id where s.xm=? and x.xxmc like ? and p.competitionId = ?",map.get("xm").toString().trim(),Qb.wrapLike(map.get("xxmc").toString().trim()),comId);
if(re!=null){
re.set("code", map.get("gwh").toString().trim());
Db.update("UPDATE CttParticipant SET code = ?
WHERE id = ?",map.get("gwh").toString().trim(), re.getLong("pid"));
re = Db.findFirst("SELECT p.id pid ,s.xm ,x.xxmc from CttParticipant p LEFT JOIN cttxs s on p.xsId=s.id LEFT JOIN CttXX x on s.xxId =x.id where s.xm=? and p.competitionId = ?",map.get("xm").toString().trim(),comId);
if(re!=null){
re.set("code", map.get("gwh").toString().trim());
Db.update("UPDATE CttParticipant SET code = ?
WHERE id = ?",map.get("gwh").toString().trim(), re.getLong("pid"));
tempXlsFile.delete();
renderEasyUISuccess("导入成功!"); }标签:原文地址:http://www.cnblogs.com/xvguang/p/5424704.html
&&国之画&&&& &&&&chrome插件&&
版权所有 京ICP备号-2
迷上了代码!javascript导出excel文件例子
方法一,测试过所有ie内核浏览器都可用
// JavaScript Document
//调用方法
var test=new PageToExcel("data",0,255,"测试.xls");//table id , 第几行开始,最后一行颜色 ,保存的文件名
test.CreateExcel(false);
test.Exec();
test.SaveAs();
test.CloseExcel();
//LastRowColor 0黑色 255红色
function PageToExcel(TableID,FirstRow,LastRowColor,SaveAsName){
this.lastRowColor=LastRowColor==""?0:LastRowC
var today=new Date();
this.saveAsName=(SaveAsName==""?today.getYear()+"年"+(today.getMonth()+1)+"月"+today.getDate()+"日.xls":SaveAsName);
this.tableId=TableID;
this.table=document.getElementById(this.tableId);//导出的table 对象
this.rows=this.table.rows.//导出的table总行数
this.colSumCols=this.table.rows(0).cells.//第一行总列数
this.fromrow=FirstR
this.beginCol=0; //起始列数
this.cols=this.colSumC
this.oSheet=
this.rowSpans=1; //行合并
this.colSpans=1; //列合并
this.colsName={0:"A",1:"B", 2:"C", 3:"D", 4:"E", 5:"F", 6:"G", 7:"H", 8:"I",9:"J", 10:"K", 11:"L", 12:"M", 13:"N", 14:"O", 15:"P", 16:"Q", 16:"R" ,18:"S", 19:"T", 20:"U", 21:"V", 22:"W", 23:"X", 24:"Y", 25:"Z"};
PageToExcel.prototype.DeleteExcelCols=function(NotShowColList){//数组NotShowColList
//this.notShowColList=NotShowColL//不显示列集合,1,2,3,1
//删除excel中的列
for(var i=0;i&NotShowColList.i++){
var temp=NotShowColList[i]-
var index=this.colsName[temp];
this.oSheet.Columns(index).D//删除
PageToExcel.prototype.CreateExcel=function(ExcelVisible)
this.oXL = new ActiveXObject("Excel.Application"); //创建应该对象
this.oXL.Visible = ExcelV
this.oWB = this.oXL .Workbooks.Add();//新建一个Excel工作簿
this.oSheet = this.oWB.ActiveS//指定要写入内容的工作表为活动工作表
//不显示网格线
this.oXL.ActiveWindow.DisplayGridlines=
}catch(e){
alert("请确认安装了非绿色版本的excel!"+e.description);
CloseExcel();
PageToExcel.prototype.CloseExcel=function()
this.oXL.DisplayAlerts =
this.oXL.Quit();
this.oXL =
this.oSheet=
PageToExcel.prototype.ChangeElementToLabel=function (ElementObj){
var GetText="";
var childres=ElementObj.childN
}catch(e){ return GetText}
if(childres.length&=0) return GetT
for(var i=0;i&childres.i++){
try{if(childres[i].style.display=="none"||childres[i].type.toLowerCase()=="hidden"){}}
catch(e){}
switch (childres[i].nodeName.toLowerCase()){
case "#text" :
GetText +=childres[i].nodeV
case "br" :
GetText +="n";
case "img" :
GetText +="";
case "select" :
GetText +=childres[i].options[childres[i].selectedIndex].innerT
case "input" :
if(childres[i].type.toLowerCase()=="submit"||childres[i].type.toLowerCase()=="button"){
GetText +="";
}else if(childres[i].type.toLowerCase()=="textarea"){
GetText +=childres[i].innerT
GetText +=childres[i].
GetText += this.ChangeElementToLabel(childres[i]);
}catch(e){}
return GetT
PageToExcel.prototype.SaveAs=function (){
this.oXL.Visible =
var fname = this.oXL.Application.GetSaveAsFilename(this.saveAsName, "Excel Spreadsheets (*.xls), *.xls");
if(fname){
this.oWB.SaveAs(fname);
this.oXL.Visible =
}catch(e){};
PageToExcel.prototype.Exec=function()
//寻找列数,考虑到第一行可能存在
for (var i=0; i&this.colSumCi++) {
var tmpcolspan = this.table.rows(0).cells(i).colS
if ( tmpcolspan&1 ) {
this.cols += tmpcolspan-1;
//定义2维容器数据,1:行;2:列;值(0 可以填充,1 已被填充)
var container=new Array(this.rows);
for (var i=0;i&this.i++) {
container[i]=new Array(this.cols);
for (j=0;j&this.j++) {
container[i][j]=0;
//将所有单元置为文本,避免非数字列被自动变成科学计数法和丢失前缀的0
this.oSheet.Range(this.oSheet.Cells(this.fromrow+1,1), this.oSheet.Cells(this.fromrow+this.rows,this.cols)).NumberFormat = "@";
for (i=0;i&this.i++){
for (j=0;j&this.j++){
//寻找开始列
for (k=j;k&this.k++){
if (container[i][k]==0) {
this.beginCol=k;
k=this. //退出循环
//此处相应跟改 根据 标签的类型,替换相关参数
this.oSheet.Cells(i+1+this.fromrow,this.beginCol+1).value = this.ChangeElementToLabel(this.table.rows(i).cells(j));
this.colSpans = this.table.rows(i).cells(j).colS
}catch(e){
this.colSpans=0
if (this.colSpans&1) {
this.oSheet.Range(this.oSheet.Cells(i+1+this.fromrow,this.beginCol+1),this.oSheet.Cells(i+1+this.fromrow,this.beginCol+this.colSpans)).Merge();
//将当前table位置填写到对应的容器中
for (k=0; k&this.colSk++) {
container[i][this.beginCol+k]= 1;
// 计算合并行
this.rowSpans = this.table.rows(i).cells(j).rowS
}catch(e){
this.rowSpans = 0;
if (this.rowSpans&1) { //行合并
this.oSheet.Range(this.oSheet.Cells(i+1+this.fromrow,this.beginCol+1),this.oSheet.Cells(i+this.rowSpans+this.fromrow,this.beginCol+this.colSpans)).Merge();
//将当前table位置填写到对应的容器中
for (k=1; k&this.rowSk++) { //由于第0行已经被colSpans对应的代码填充了,故这里从第1行开始
for (l=0;l&this.colSl++) {
container[i+k][this.beginCol+l]=1;
//如果开始列+合并列已经等于列数了,故不需要再循环 table
if (this.beginCol+this.colSpans&=this.cols) j=this.
this.oSheet.Range(this.oSheet.Cells(1,1), this.oSheet.Cells(1,1)).Font.Size=20;
this.oSheet.Range(this.oSheet.Cells(1,1), this.oSheet.Cells(1,1)).Font.Bold =
this.oSheet.Range(this.oSheet.Cells(1,1), this.oSheet.Cells(1,1)).HorizontalAlignment = -4108; //居中
this.oSheet.Range(this.oSheet.Cells(1,1), this.oSheet.Cells(1,1)).Rows.RowHeight = 40;
//自动调整行高
//最后一行是否空色
this.oSheet.Range(this.oSheet.Cells(this.rows,1), this.oSheet.Cells(this.rows,1)).Font.Color=this.lastRowC
}catch(e){}
this.oSheet.Range(this.oSheet.Cells(this.fromrow+2,1), this.oSheet.Cells(this.fromrow+this.rows,this.cols)).Rows.RowHeight=20;
this.oSheet.Range(this.oSheet.Cells(this.fromrow+2,1), this.oSheet.Cells(this.fromrow+this.rows,this.cols)).Font.Size=10;
//自动换行
this.oSheet.Range(this.oSheet.Cells(this.fromrow+2,1), this.oSheet.Cells(this.fromrow+this.rows,this.cols)).WrapText =
//自动调整列宽
this.oSheet.Range(this.oSheet.Cells(this.fromrow+1,1), this.oSheet.Cells(this.fromrow+this.rows,this.cols)).Columns.AutoFit();
this.oSheet.Range(this.oSheet.Cells(this.fromrow+1,1), this.oSheet.Cells(this.fromrow+this.rows,this.cols)).Borders.LineStyle = -4118;
return this.
方法二,同样支持所有ie内核浏览器
新建一个exportPrint.html页面,里面的代码如下所示,就可以实现导出到Excel和打印网页。
&title&IE浏览器使用JS技术导出到Excel和打印&/title&
.table_stat {
border-right:0
border-bottom:0
border-left:1px solid #819BD8;
border-top:1px solid #819BD8;
.td_stat {
border-right:1px solid #819BD8;
border-bottom:1px solid #819BD8;
&object classid="CLSID:A-11DO-A96B-00C04FD705A2" height="0" id="WebBrowser" width="0"&&/object&
&table width="100%" align="center" border="0" cellpadding="0" cellspacing="0" style="text-align:" class="table_stat"&
&td id="title" align="center" nowrap="nowrap" class="td_stat" colspan="2"&
&td id="title" align="center" nowrap="nowrap" class="td_stat" colspan="1"&
&td id="title" align="center" nowrap="nowrap" class="td_stat" colspan="1"&
&td id="title" align="center" nowrap="nowrap" class="td_stat" colspan="2"&
&input type="button" id="export" value="导出" onclick="javascript:exportToExcel();" &
&input type="button" id="print" value="打印" onclick="javascript:print();" &
&script type="text/javaScript"&
//导出到Excel
function exportToExcel() {
if(document.getElementById("title")) {
var oRangeRef = document.body.createTextRange();
oRangeRef.execCommand("Copy");
var appExcel = new ActiveXObject("Excel.Application");
appExcel.visible =
appExcel.Workbooks.Add().WorkSheets.Item(1).Paste();
} catch(e) {
alert("出错啦!可能是浏览器或者是数据量太大咯哦!");
appExcel =
oRangeRef =
function print() {
if(document.getElementById("title")) {
var export = document.getElementById("export");
var print = document.getElementById("print");
export.style.display = "none";
print.style.display = "none";
document.all.WebBrowser.ExecWB(6,1);
} catch(e) {
alert("出错啦!可能是浏览器或者是数据量太大咯哦!");
export.style.display = "";
print.style.display = "";

我要回帖

更多关于 导出excel 文件已损坏 的文章

 

随机推荐