st.web;
/**
* 功能:主要实现数据导出Excel和Word功能
* 日期:2008-2-28
*/
import ais.basic.service.BasicUtil;
import aismons.file.service.FileService;
import ais.framework.web.BaseAction;
st.model.Employeer;
st.service.IemployeerService;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
DecimalFormat;
import jxl.write.NumberFormat;
import java.util.List;
import javax.servlet.ServletOutputStream;
import jxl.Cell;
import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.UnderlineStyle;
import jxl.format.VerticalAlignment;
text align centerimport jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.BoldStyle;
import jxl.format.Colour;
import jxl.write.Blank;
import jxl.write.DateFormat;
import jxl.write.DateTime;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableImage;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
//import com.SimpleDateFormat;
//import Cell;
import Document;
import Font;
import Image;
import PageSize;
import Paragraph;
import Table;
import pdf.BaseFont;
import tf.RtfWriter2;
import java.awt.Color;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.struts2.ServletActionContext;
public class ExportAction extends BaseAction{
/**
*
*/
private static final long serialVersionUID = -3951404867065653031L;
FileService fileService;
BasicUtil basicUtil;
IemployeerService iemployeerService;
Employeer employeer;
String filename=System.currentTimeMillis()+".doc";
public ExportAction() {}
/**
* 功能:将数据库中的数据导出word
* 日期:2008-2-29
* @return
*/
// 复制一份新的RTF文件
public String getNewFilePath() throws Exception {
InputStream ins = ServletContext().getResourceAsStream("/empty.doc");
byte[] b = new byte[ins.available()];
ad(b);
ins.close();
String newFileName = ServletContext().getRealPath("")+ "/"+filename;
OutputStream ous = new FileOutputStream(newFileName);
ous.write(b);
ous.close();
return newFileName;
}
// 将二进制流写到客户端
public void writeNewFile(String newFilePath, String downloadFileName)
throws Exception {
File f = new File(newFilePath);
InputStream ins = new FileInputStream(f);
byte[] b = new byte[ins.available()];
ad(b);
ins.close();
/* <option value="image/bmp">BMP</option>
<option value="image/gif">GIF</option>
<option value="image/jpeg">JPEG</option>
<option value="image/tiff">TIFF</option>
<option value="image/x-dcx">DCX</option>
<option value="image/x-pcx">PCX</option>
<option value="text/html">HTML</option>
<option value="text/plain">TXT</option>
<option value="text/xml">XML</option>
<option value="application/afp">AFP</option>
<option value="application/pdf">PDF</option>
<option value="application/pdf">zip</option>
<option value="application/rtf">RTF</option>
<option value="application/msword">MSWORD</option>
<option value="application/vnd.ms-excel">MSEXCEL</option>
<option value="application/vnd.ms-powerpoint">MSPOWERPOINT</option>
<option value="application/wordperfect5.1">WORDPERFECT</option>
<option value="application/vnd.lotus-wordpro">WORDPRO</option>
<option value="application/vnd.visio">VISIO</option>
<option value="application/vnd.framemaker">FRAMEMAKER</option>
<option value="application/vnd.lotus-1-2-3">LOTUS123</option>*/
/**
* 出现保存与打开对话框application/octet-stream,加上下面第二句是保存时能正确出现文件类型
*/
//getResponse().setContentType("application/octet-stream");
//getResponse().setHeader("Content-Disposition","attachment;filename=\""+ new String((downloadFileName).getBytes(),"ISO-8859-1") + "\";");
/**
* 直接打开word文档
*/
getResponse().setContentType("application/msword");
Response().getOutputStream().write(b);
//文件删除
if (f != null) {
f.delete();
}
}
/**
* @param em_name 姓名
* @param em_sex 性别
* @param em_age 年龄
* @param em_duty 职务
* @param em_pay 工资
* @param em_polity 政治面貌
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论