81,094
社区成员
发帖
与我相关
我的任务
分享
/**
* 文档下载
*/
public void exportWord() throws UIException {
try {
Houseapplydateit houseapplydateit = new Houseapplydateit();
// 将form bean的值拷贝给value bean
CopyBeanProperty.copyProperties(houseapplydateit,
houseapplydateitForm);
List<Houseapplyupreportdateit> list = houseapplydateitForm
.getList();
if (houseapplydateit != null) {
Configuration configuration = new Configuration();
configuration.setDefaultEncoding("utf-8");
Map<String, Object> data = new Hashtable<String, Object>();
for (int i = 0; i < list.size(); i++) {
data.put("ID", list.get(i).getCompID().getApplyId());
data.put("YearBatch", houseapplydateit.getNoticeYear()
+ "年" + houseapplydateit.getNoticeBatch() + "批");
String name = ucAreaInfoBO.getUcAreaInfo(
list.get(i).getCommunityAreano()).getAreaname();
data.put("Areaname", name);
name = ucAreaInfoBO.getUcAreaInfo(
list.get(i).getVillageAreano()).getAreaname();
data.put("villageAreano", name);
data.put("applyuserName", list.get(i).getApplyuserName());
data.put("familyValidUsernum", list.get(i)
.getFamilyValidUsernum());
data.put("nowhouseArea", list.get(i).getNowhouseArea());
data.put("demolishArea", list.get(i).getDemolishArea());
data.put("reformArea", list.get(i).getReformArea());
if (houseapplydateit.getUpreportStatus() == 1) {
if (list.get(i).getIsOk() == 1) {
data.put("isOk", "审批通过");
} else {
data.put("isOk", "审批不通过");
}
} else {
data.put("isOk", "街道未审批");
}
configuration.setClassForTemplateLoading(getClass(),
Config.getProperty("upreportTemplatePath"));
Template t = null;
t = configuration.getTemplate(Config
.getProperty("upreportTemplateFtl"));
t.setEncoding("gbk");
fileName = houseapplydateit.getNoticeYear() + "年"
+ houseapplydateit.getNoticeBatch() + "批" + ".doc";
this.fileName = new String(this.fileName.getBytes("GBK"),
"utf-8");
ActionContext ctx = ActionContext.getContext();
HttpServletResponse response = (HttpServletResponse) ctx
.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse");
response.setContentType("application/msword");
response.addHeader("Content-Disposition",
"attachment; filename=" + fileName);
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
out.close();
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
function AllAreaWord()
{
alert("ss");
var oWD = new ActiveXObject("Word.Application");
var oDC = oWD.Documents.Add("",0,1);
var oRange =oDC.Range(0,1);
var sel = document.body.createTextRange();
sel.moveToElementText(PrintA);
sel.select();
sel.execCommand("Copy");
oRange.Paste();
oWD.Application.Visible = true;
//window.close();
}
方法可以进入,但是到
var oWD = new ActiveXObject("Word.Application");时就运行不下去了!是不是什么文件没有导入???<HTML>
<HEAD>
<title>WEB页面导出为EXCEL文档的方法
</title>
</HEAD>
<body>
<BR>
<table id = "PrintA" width="100%" border="1" cellspacing="0" cellpadding="0" bgcolor = "#61FF13">
<TR style="text-align : center;">
<TD>单元格A</TD>
<TD>单元格A</TD>
<TD>单元格A</TD>
<TD>单元格A</TD>
</TR>
<TR>
<TD colSpan=4 style="text-align : center;"><font color="BLUE" face="Verdana">单元格合并行A</FONT></TD>
</TR>
</TABLE>
<BR>
<table id = "PrintB" width="100%" border="1" cellspacing="0" cellpadding="0">
<TR style="text-align : center;">
<TD>单元格B</TD>
<TD>单元格B</TD>
<TD>单元格B</TD>
<TD>单元格B</TD>
</TR>
<TR>
<TD colSpan=4 style="text-align : center;">单元格合并行B</TD>
</TR>
</TABLE>
<br><br><br>
<input type="button" onclick="javascript:AllAreaWord();" value="导出页面指定区域内容到Word">
<input type="button" onclick="javascript:AllAreaExcel();" value="导出页面指定区域内容到Excel">
<input type="button" onclick="javascript:CellAreaExcel();" value="导出表单单元格内容到Excel">
<SCRIPT LANGUAGE="javascript">
//指定页面区域内容导入Excel
function AllAreaExcel()
{
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var sel=document.body.createTextRange();
sel.moveToElementText(PrintA);
sel.select();
sel.execCommand("Copy");
oSheet.Paste();
oXL.Visible = true;
}
//指定页面区域“单元格”内容导入Excel
function CellAreaExcel()
{
var oXL = new ActiveXObject("Excel.Application");
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
var Lenr = PrintA.rows.length;
for (i=0;i<Lenr;i++)
{
var Lenc = PrintA.rows(i).cells.length;
for (j=0;j<Lenc;j++)
{
oSheet.Cells(i+1,j+1).value = PrintA.rows(i).cells(j).innerText;
}
}
oXL.Visible = true;
}
//指定页面区域内容导入Word
function AllAreaWord()
{
var oWD = new ActiveXObject("Word.Application");
var oDC = oWD.Documents.Add("",0,1);
var oRange =oDC.Range(0,1);
var sel = document.body.createTextRange();
sel.moveToElementText(PrintA);
sel.select();
sel.execCommand("Copy");
oRange.Paste();
oWD.Application.Visible = true;
//window.close();
}
</SCRIPT>
</body></html>
<meta http-equiv="X-UA-Compatible" content="IE=7" >
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" >
[/quote]
要到安全设置里面去该设置!<meta http-equiv="X-UA-Compatible" content="IE=7" >
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" >