在JSP里将页面上的数据导入到Excel后,如何设置表格的宽度???

kissdavid 2004-09-06 03:06:57
在JSP里将页面上的数据导入到Excel后,如何设置表格的宽度???
<%@page contentType="application/vnd.ms-excel; charset=gb2312"%>
上面是导入的语法,导入后字体将会不换行显示,我在页面上都是设置了宽度的,但一导到Excel就变成了将文字横排。请会的朋友帮帮忙,解决问题立即给分!
...全文
840 点赞 收藏 19
写回复
19 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
djinzaghi 2004-09-21
用<br>最简单了。
回复
mbl 2004-09-14
gz
回复
kissdavid 2004-09-09
我已经配置好了jxl
我用的是<%@page contentType="application/vnd.ms-excel; charset=gb2312"%>
方法将jsp上的数据生成excel
我在jsp能用jxl设置宽度吗?如何设置?
回复
demon007 2004-09-09
再来多点


<%
String sd = m_sd;
String ed = m_ed;
String titleSheet = sd + "-" + ed;
%>
<%
WritableWorkbook workbook = null;
ArrayList fileNameList = new ArrayList();
%>
<%
int startRow = 0;
int endRow = 0;
int index = 0;
for(int i=0;i<records.size();i++)
{
if((i%perBookSize)==0)
{
startRow = i;
endRow = startRow + perBookSize;

StringBuffer filebuf = new StringBuffer();
filebuf.append(sd).append("-").append(ed);
if( m_selCustomerID.equals("key")
&& m_icustomerName!=null
&& m_icustomerName.trim().length()>0 )
{
filebuf.append("-").append(m_icustomerName);
}
if( records.size()>perBookSize )
{
// 多个文件
filebuf.append("-").append(index);
}
filebuf.append(".csv");

fileNameList.add(filebuf.toString());

String filename = filebuf.toString();
File file = new File(filename);

workbook = Workbook.createWorkbook(file);
WritableSheet sheet = workbook.createSheet(String.valueOf(titleSheet.toString()), 1);
%>
<%
StringBuffer strStatFee = new StringBuffer();
strStatFee.append(strStatText).append(totalMoney).append(strYuanUnit);
strStatFee.append(" ").append(strInFeeText).append(inMoney).append(strYuanUnit);
strStatFee.append(" ").append(strOutFeeText).append(outMoney).append(strYuanUnit);

Label lblStat = new Label(0, statRow, strStatFee.toString());
sheet.mergeCells(0, statRow, 4, statRow);
sheet.addCell(lblStat);

// sheet title
Label lblTitle = new Label(0, titleRow, strTitleText, fmtCenterTitle);
sheet.mergeCells(0, titleRow, 4, titleRow);
sheet.addCell(lblTitle);
%>
<%
String strQryTimeText = strQueryTimeText + sd + "-" + ed;
%>
<%
// print startime && endtime
Label lblPrintTime = new Label(0, printTimeRow,strQryTimeText);
sheet.mergeCells(0, printTimeRow, 4, printTimeRow);
sheet.addCell(lblPrintTime);
%>
<%
// Define each Column Caption in Table
Label lblColumn = null;

lblColumn = new Label(0, colRow, strRowid, fmtCenterCaption);
sheet.addCell(lblColumn);
lblColumn = new Label(1, colRow, strCustomerName, fmtCenterCaption);
sheet.addCell(lblColumn);
lblColumn = new Label(2, colRow, strCaller, fmtCenterCaption);
sheet.addCell(lblColumn);
lblColumn = new Label(3, colRow, strCallee, fmtCenterCaption);
sheet.addCell(lblColumn);
lblColumn = new Label(4, colRow, strStartdate, fmtCenterCaption);
sheet.addCell(lblColumn);
lblColumn = new Label(5, colRow, strTimelong, fmtCenterCaption);
sheet.addCell(lblColumn);
lblColumn = new Label(6, colRow, strRate, fmtCenterCaption);
sheet.addCell(lblColumn);
lblColumn = new Label(7, colRow, strMoney, fmtCenterCaption);
sheet.addCell(lblColumn);
lblColumn = new Label(8, colRow, strCallType, fmtCenterCaption);
sheet.addCell(lblColumn);

endRow = (endRow>records.size())?records.size():endRow;
int rowPos = recordRow;

for(int j=startRow;j<endRow;j++)
{
rowPos++;

BillRecord data = (BillRecord)records.get(j);

// Label rowId = new Label(0, rowPos, data.getRowID());
jxl.write.Number rowId = new jxl.write.Number(0, rowPos, Long.parseLong(data.getRowID()), wclN);
sheet.addCell(rowId);

Label customerName = new Label(1, rowPos, data.getCustomerName(),wclN);
sheet.addCell(customerName);

// Label caller = new Label(2, rowPos, data.getDialNum());
String sDialNum = data.getCallerNum();
sDialNum = (sDialNum.trim().length()==0)?"0":sDialNum;
jxl.write.Number caller = new jxl.write.Number(2, rowPos, Long.parseLong(sDialNum), wclN);
sheet.addCell(caller);

Label callee = new Label(3, rowPos, data.getCalleeNum(),wclN);
sheet.addCell(callee);

Label lblStartDate = new Label(4, rowPos, data.getStartTime(),wclN);
sheet.addCell(lblStartDate);

Label timelong = new Label(5, rowPos, data.getTimeLong(),wclN);
sheet.addCell(timelong);

jxl.write.Number rate = new jxl.write.Number(6, rowPos, Float.parseFloat(data.getTariff()), wcfN);
sheet.addCell(rate);

jxl.write.Number money = new jxl.write.Number(7,rowPos, Float.parseFloat(data.getTicketFee()), wcfN);
sheet.addCell(money);

Label lblCallType = new Label(8, rowPos, BillRes.getCallType(data.getCallType()),wclN);
sheet.addCell(lblCallType);

}

sheet.setColumnView(0, 5);
sheet.setColumnView(1, 30);
sheet.setColumnView(2, 12);
sheet.setColumnView(3, 18);
sheet.setColumnView(4, 25);
sheet.setColumnView(5, 15);
sheet.setColumnView(6, 12);
sheet.setColumnView(7, 15);
sheet.setColumnView(8, 15);

workbook.write();
workbook.close();
index++;
}
}

ZipTool zip = new ZipTool();
// zip.outputStream(zipName,fileNameList,response.getOutputStream());

String webTempPath = application.getRealPath("/temp");

GregorianCalendar cal = (GregorianCalendar)Calendar.getInstance();

StringBuffer fileDirBuf = new StringBuffer();
fileDirBuf.append(webTempPath).append("/").append(cal.get(Calendar.YEAR)).append(cal.get(Calendar.MONTH)+1).append(cal.get(Calendar.DATE));

File filedir = new File(fileDirBuf.toString());
if(!filedir.exists())
{
filedir.mkdir();
}
String zipFile = filedir.getAbsolutePath() + "/" + zipNameBuf.toString();
zip.createZip(zipFile,fileNameList);

%>
回复
demon007 2004-09-09
sheet.setColumnView(0, 5);
sheet.setColumnView(1, 30);
sheet.setColumnView(2, 12);
sheet.setColumnView(3, 18);
sheet.setColumnView(4, 25);
sheet.setColumnView(5, 15);
sheet.setColumnView(6, 12);
sheet.setColumnView(7, 15);
sheet.setColumnView(8, 15);
回复
pirloxiao 2004-09-08
楼上的方法可以!
回复
mor 2004-09-08
me的办法(JXL):
在new Label时,设定的WritableCellFormat里设setWrap(true);//自动换行
然后设定这个列的宽度:WritableSheet的方法setColumnView(int 列序号,int 宽度)

JXL的文档:

public void setColumnView(int col,int width)
Sets the width of the column on this sheet, in characters. This causes Excel to resize the entire column. If the columns specified already has view information associated with it, then it is replaced by the new data

Parameters:
col - the column to be formatted
width - the width of the column //注意这里的宽度是按字符数来算的
回复
kissdavid 2004-09-08
asd
回复
kissdavid 2004-09-07
我现在的问题就是导过去的表格宽度不能自动设置,只能是按字的多少来排,这样就没法设置表格的样试了!
回复
sbb928 2004-09-07
我研究JEXCEL,我的MSN是binbin981928@hotmail.com,加我细聊
回复
zhonghua2003 2004-09-07
怎么打数据导入Excel啊?
回复
kissdavid 2004-09-07
。。。
回复
kissdavid 2004-09-07
asdf
回复
kissdavid 2004-09-06
这两个我都没用过!
回复
zhugang 2004-09-06
用jxl
回复
ligenlee 2004-09-06
poi jxl都可以
这个你可能要去查excel的api
回复
lenoli 2004-09-06
设置不了
回复
kissdavid 2004-09-06
目前我只能用这种方法做打印!
回复
用POI我就会,这个不行的
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-06 03:06
社区公告
暂无公告