可以的,但是構(gòu)造方法的引用必須寫在當(dāng)前構(gòu)造函數(shù)的第一句:this();//有參數(shù)的要寫參數(shù)。
創(chuàng)新互聯(lián)長期為上千客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為嘉蔭企業(yè)提供專業(yè)的網(wǎng)站制作、做網(wǎng)站,嘉蔭網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
一:頁面圖片顯示預(yù)覽:
1)如下圖:
2)點(diǎn)擊導(dǎo)出按鈕后預(yù)覽:
3)最終生成的excel表格圖片預(yù)覽:
二:代碼演示:
說明:執(zhí)行操作時,請先引進(jìn)導(dǎo)出excel表格的jar文件包。
找到導(dǎo)出按鈕所執(zhí)行的js方法,在java后天查看該方法的實(shí)現(xiàn)即可。
1)jsp代碼:
[html]?view plaincopyprint?
%@?page?language="java"?import="java.util.*"?pageEncoding="UTF-8"%
%@taglib?prefix="s"?uri="/struts-tags"?%
%
String?path?=?request.getContextPath();
String?basePath?=?request.getScheme()?+?"://"
+?request.getServerName()?+?":"?+?request.getServerPort()
+?path?+?"/";
%
html
head
base?href="%=basePath%"
title駕校合格率排名/title
link?href="jsp/commonstyle/css/tabStyle.css"?rel="stylesheet"?type="text/css"
link?rel="STYLESHEET"?type="text/css"?href="%=basePath%jsp/hgltj/js/tablesort.css"
script?type="text/javascript"?src="%=basePath%jsp/system/common/js/publicColor.js"/script
script?type="text/javascript"?src="jsp/commonstyle/js/js/My97DatePicker/WdatePicker.js"?defer="defer"/script
script?type="text/javascript"?src="%=basePath%jsp/hgltj/js/tablesort.js"/script
script?language="JavaScript"
function?load()
{
//根據(jù)分辨率設(shè)置表格大小
maxw=document.getElementById("maintb").offsetWidth;
if(maxw824){//1024分辨率未展開
mainbox.width="98%";
}?else?if(maxw1013){//1024分辨率展開
mainbox.width="98%";
}?else??if(maxw1081){//1280分辨率未展開
mainbox.width="95%";
}?else??if(maxw1270){//1280分辨未展開
mainbox.width="95%";
}else{//1280以上分辨展開
mainbox.width="98%";
}
}
/script
script
function?overIt(){
var?the_obj?=?event.srcElement;
if(the_obj.tagName.toLowerCase()?==?"td"){
the_obj=the_obj.parentElement;
the_obj.oBgc=the_obj.currentStyle.backgroundColor;
the_obj.oFc=the_obj.currentStyle.color;
the_obj.style.backgroundColor='#4073C4';
the_obj.style.color='#ffffff';
the_obj.style.textDecoration='underline';
}
}
function?outIt(){
var?the_obj?=?event.srcElement;
if(the_obj.tagName.toLowerCase()?==?"td"){
the_obj=the_obj.parentElement;
the_obj.style.backgroundColor=the_obj.oBgc;
the_obj.style.color=the_obj.oFc;
the_obj.style.textDecoration='';
}
}
function?serch(){
document.getElementById("formName").action="%=basePath?%hgltj.action?method=getHglpm";
document.getElementById("formName").submit();
}
function?tbbt(){
var?jzrq=document.getElementById("jzrqId").value;
//var?jxmc=document.getElementById("jxmcId").value;
window.open('%=basePath?%hgltj.action?method=getHglpmTbtjjxkshgl.jzrq='+jzrq+'tjjxkshgl.zt='+1,'','height=650,width=1250,top=150,left=200,toobar=no,menubar=no,scrollbars=yes,resizable=no,location=no,');
}
function?openwd(){
document.getElementById("formName").action="%=basePath?%hgltj.action?method=downJxhglPm";
document.getElementById("formName").submit();
}
/script
/head
BODY?onLoad="load()"?style="background:?url(images/cont_bg.gif);?background-repeat:?repeat-y"
input?type="hidden"?name="method"?value="getDriverInfoList"/
table?border="0"?width="100%"?cellspacing="0"?cellpadding="0"?id="maintb"
tr
td?align="center"
table?width="90%"??border="0"??cellspacing="0"?cellpadding="0"?id="mainbox"?style="background:url(jsp/commonstyle/images/usermessage_02.gif);?background-repeat:repeat-x;"?
!--寬度可變內(nèi)容框--
tr?
td?width="33"?height="27"?style="?background:url(jsp/commonstyle/images/usermessage_01.gif);?background-position:left;?background-repeat:no-repeat;"?/td
td?width="965"?class="style1"font?color="black"駕校合格率排名/font/td
td?width="14"?height="27"?style="?background:url(jsp/commonstyle/images/usermessage_03.gif);?background-position:right;?background-repeat:no-repeat;"?/td
/tr
tr
td?colspan="3"
!--頁面主體內(nèi)容開始--
!--查詢條件--
form?action=""?name="formName"?method="post"?style="margin:0px"?id="formName"?theme="simple"
table?width="100%"?border="0"?cellpadding="0"?cellspacing="0"???style="border-collapse:collapse;"?id="tj"?align="center"
tr?align="left"
td?class="tjbg1"?style="text-align:?left"
!--?input?type="hidden"?id="method"??name="method"?value="getHglpm"/?--
統(tǒng)計(jì)日期:
input?type="text"?name="tjjxkshgl.jzrq"?id="jzrqId"?value="s:property?value="tjjxkshgl.jzrq"/"?onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM'})"/
!--?駕校名稱:
s:select?id="jxmcId"??name="tjjxkshgl.jxxh"??value="tjjxkshgl.jxxh"?list="schoolList"?listKey="jxxh"?listValue="jxmc"?headerKey=""?headerValue="--請選擇--"?theme="simple"/s:select????????--
input?name="input"?value="?統(tǒng)?計(jì)?"?type="button"?class="normalbtn"?onClick="serch()"?style="margin-bottom:?5px"?/
input?name="input"?type="button"?value="?合格率圖表?"?onclick="tbbt()"?class="normalbtn"?style="margin-bottom:?5px"?/
input?id="Button1"?type="button"?value="?導(dǎo)?出?"?onclick="openwd();"?class="normalbtn"?style="margin-bottom:?5px"?/
/td
/tr
/table!--查詢結(jié)果--
/form
!--查詢結(jié)果--
table?width="100%"?border="0"?cellpadding="4"?cellspacing="1"?bgcolor="#abcfff"?id="cxjg"?align="center"
thead
tr?class="tbtitle"
td?width="4%"?align="center"?class="t1"名次/td
td?width="8%"?align="center"?class="t1"名稱/td
td?class="t1"?width="5%"?align="center"科目一/td
td?class="t1"?width="5%"?align="center"科目二/td
td?class="t1"?width="5%"?align="center"科目三/td
td?class="t1"?width="5%"?align="center"平均合格率/td
td?class="t1"?width="5%"?align="center"操作/td
/tr
/thead
s:iterator?id="jxhgl"?value="jxhelpmList"?status="st"
tr?class="changeColor"?onMouseOver="overIt()"?onMouseOut="outIt()"?style="cursor:?hand"?align="center"
tds:property?value="#st.index+1"http://td
tds:property?value="#jxhgl.jxmc"http://td
tds:property?value="#jxhgl.km1hgl"http://td
tds:property?value="#jxhgl.km2hgl"http://td
tds:property?value="#jxhgl.km3hgl"http://td
tds:property?value="#jxhgl.avghgl"/%/td
td
a?href="javascript:"?onclick="openWin('%=basePath?%hgltj.action?method=getTbForJxxhtjjxkshgl.jxxh=s:property?value="#jxhgl.jxxh"/tjjxkshgl.zt=1','',1250,750);"圖表/a
/td
/tr
/s:iterator
/table
/table
/td
/tr
/table
/body
/html
2)java代碼演示:
[java]?view plaincopyprint?
/**
*?駕校合格率導(dǎo)出excel圖表
*/
//response.getOutputStream();//?取得輸出流
response.reset();//?清空輸出流
String?tmptitle?=?"駕校合格率排名";?//?標(biāo)題
response.setHeader("Content-disposition",?"attachment;?filename="+new?String(tmptitle.getBytes(),"iso8859-1")+".xls");//?設(shè)定輸出文件頭
response.setContentType("application/vnd.ms-excel");//?定義輸出類型
wbook?=?Workbook.createWorkbook(os);?//?建立excel文件
WritableSheet?wsheet?=?wbook.createSheet(tmptitle,?0);?//?sheet名稱
//?設(shè)置excel標(biāo)題
//cellFormat.setBackground(Colour.AQUA);
cellFormat.setFont(wfont);
label.setCellFormat(cellFormat);
wsheet.addCell(label);
//wsheet.addCell(new?Label(0,?0,?tmptitle,?wcfFC));
wsheet.setRowView(0,500);?//第一行高度
wsheet.mergeCells(0,?0,?6,?1);??//合并單元格(第一列的第一行和第七列的第二行合并)
//wsheet.mergeCells(0,?1,?9,?1);
//??????wsheet.mergeCells(0,?2,?0,?4);
//??????wsheet.mergeCells(1,?2,?3,?2);
//??????wsheet.mergeCells(4,?2,?6,?2);
//??????wsheet.mergeCells(7,?2,?9,?2);
wsheet.setColumnView(0,10);?//寬度
wsheet.setColumnView(1,25);?//寬度
wsheet.setColumnView(2,10);?//寬度
wsheet.setColumnView(3,10);?//寬度
wsheet.setColumnView(4,10);?//寬度
wsheet.setColumnView(5,10);?//寬度
//?開始生成主體內(nèi)容
wfont?=?new?jxl.write.WritableFont(WritableFont.ARIAL,?14,WritableFont.BOLD,false,?UnderlineStyle.NO_UNDERLINE,Colour.BLACK);
wcfFC?=?new?WritableCellFormat(wfont);
wsheet.addCell(new?Label(0,?2,?"名次",wcfFC));
wsheet.addCell(new?Label(1,?2,?"駕校名稱",wcfFC));
wsheet.addCell(new?Label(2,?2,?"科目一",wcfFC));
wsheet.addCell(new?Label(3,?2,?"科目二",wcfFC));
wsheet.addCell(new?Label(4,?2,?"科目三",wcfFC));
wsheet.addCell(new?Label(5,?2,?"合格率",wcfFC));
int?count=jxhelpmList.size();
if(count0){??////判斷集合是否不為0
TjJxkshgl?tjhgl=null;
for(int?i=0;ijxhelpmList.size();i++){
tjhgl=(TjJxkshgl)jxhelpmList.get(i);
wsheet.addCell(new?Label(0,?i+3,?(i+1)+""));
wsheet.addCell(new?Label(1,?i+3,?tjhgl.getJxmc()));
wsheet.addCell(new?Label(2,?i+3,?tjhgl.getKm1hgl()));
wsheet.addCell(new?Label(3,?i+3,?tjhgl.getKm2hgl()));
wsheet.addCell(new?Label(4,?i+3,?tjhgl.getKm3hgl()));
wsheet.addCell(new?Label(5,?i+3,?tjhgl.getAvghgl()));
}
代碼方法如下,從流加載wps文件,轉(zhuǎn)為pdf格式
import com.spire.doc.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class WordToPDF {
public static void main(String[] args)throws IOException {
FileInputStream inputStream = new FileInputStream(new File("test.wps"));
Document document = new Document();
document.loadFromStream(inputStream, FileFormat.Doc);
document.saveToFile("WPStoPDF.pdf",FileFormat.PDF);
}
}
在程序中需引入 spire.doc.jar。
可以通過流的方式加載.wps文檔,下面以讀取文檔中的文字保存到本地為例,你參考看看如何讀取的。
import com.spire.doc.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
public class ReadTextFromWPS {
public static void main(String[] args) throws IOException{
//通過流加載WPS文字文檔
FileInputStream inputStream = new FileInputStream(new File("test.wps"));
Document doc = new Document();
doc.loadFromStream(inputStream, FileFormat.Doc);
//獲取文本保存為String
String text = doc.getText();
//將String寫入Txt
writeStringToTxt(text,"讀取WPS文本.txt");
}
public static void writeStringToTxt(String content, String txtFileName) throws IOException {
FileWriter fWriter= new FileWriter(txtFileName,true);
try {
fWriter.write(content);
}catch(IOException ex){
ex.printStackTrace();
}finally{
try{
fWriter.flush();
fWriter.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
讀取結(jié)果:
注意在程序中導(dǎo)入spire.doc.jar。
網(wǎng)頁標(biāo)題:java代碼中集成wps java項(xiàng)目整合wps
URL網(wǎng)址:http://m.rwnh.cn/article24/ddosjje.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、外貿(mào)建站、網(wǎng)站設(shè)計(jì)、品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、網(wǎng)站導(dǎo)航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)