這是不能復制下來的,就像vi裡面的高亮等一樣,你復制的是文本,格式是不能像把word文檔復制到word文檔那樣連格式同時復制的
B. eclipse導入工程後 如何讓有問題的文件顯示紅叉 具體操作請說明
eclipse中只要build wordkspace後有錯誤的都是以紅叉叉顯示。
1、找到不提示錯誤的工程項目,在項目上滑鼠右鍵,選擇Properties,如下圖:
按照上圖設置好參數後,點擊apply在點擊OK按鈕即可。
C. 怎樣增強MyEclipse的代碼自動提示功能
Myeclipse的代碼提示功能沒有發揮作用,一般是因為快捷鍵沖突的原因,導致了Myeclipse快捷鍵無法使用。那麼該怎樣解決這樣的問題呢?下面來跟我一起解決吧!(新安裝Myeclipse或者由於誤操作,經常會出現此類問題):
首先打開Myeclipse,出現此類問題,多數是因為設置原因,這里我們打開Myeclipse的偏好設置,來對快捷鍵進行重新設置。
我們先來看下Myeclipse的強大的提示功能吧:如下圖所示:
只要在Myeclipse的java代碼中敲入syso,就可以自動顯示出輸出語句System.out.println();而不用手動敲出所有代碼,這功能夠炫吧!
Myeclipse的代碼提示功能圖示
首先我們點擊進入菜單欄中的Window-Perference,選擇Perference。
進入偏好設置界面後,在文本框中輸入keys,進入快捷鍵設置界面。
點擊進入後會看到快捷設置界面,我們在圖中文本框中輸入ALT+/,這個是工具默認的快捷提示,如果你想更改,可以使用你喜歡的組合鍵來進行設置。
在這里我們將第二個去掉,Content Assist就是工具默認的快捷鍵。直接將wordCompletion刪除,先點擊wordCompletion,然後將下面的快捷鍵設置刪掉就行了。
下面的就是設置如何將沖突的快捷鍵刪除。
最後點擊Apply,然後確定保存設置就行了,接下來快捷鍵就可以使用了,在代碼界面直接直接按住Alt+/就行了。如下圖所示,這里演示的是一個main方法的畫面。
上面就是直接輸入main就可以就出main函數。很方便吧!
D. 請問eclipse下復制代碼時如何將代碼前面的行號也復制下來
那個是eclipse開發環境裡面的行號顯示功能,是不能復制的,如果你僅僅是想看著舒服回,就可以直接復制到文答本文件中然後用ultraedit或者notepad++這樣的程序打開,也是自帶行號的,如果你是要貼到網頁中,有些論壇是提供這樣的功能的。或者你自己可以寫一個簡單的程序來自動添加行號,主要是在換行符後面添加進行號即可,實現起來也很簡單。希望採納
E. 用iReport導出的txt文件中中文部分成了亂碼,這是什麼原因,如何解決
安裝就不用說了,但是要理解Ireport和JasperReport的關系十分重要,Ireport是設計報表的圖形界面,在Ireport里新建一個報表是以.jrxml的形式保存的,而最終要用到的是將.jrxml的文件編譯為.jsper的文件。.jasper文件就是JaserReport需要調用的報表模版,JasperReport的強大功能就在於它能將.jasper轉化為各種文件的格式,如xls,rtf,pdf等等最常用的文件格式。
要將.jsper文件應用在項目中,首先要做幾樣准備工作:
1.將安裝好的Ireport,找到它下面的lib目錄,再把jasperreports-1.3.0.jar這個包復制出來(這個包是JasperReport導出的關鍵),然後將這個包導入到需要應用的項目中,然後在eclipse中重新構建整個項目,這是最關鍵的第一步。
2.如果導出出現亂碼的問題,需要引入iText亞洲語言包,可以在 http://www.lowagie.com/iText/ 查看關於iText的相關信息,包括源代碼,文檔.
3.設計好報表,將報表編譯為.jsper文件,這些文件在iReport的安裝路徑下,很容易找到。
現在萬事俱備,只欠東風了。我在開始寫程序的的時候,在網上找了好些代碼,而導出的過程中用到的類 JRRtfExporter 的源代碼也踩過,並且發現了 http://www.koders.com 這個非常好的網站,這是開源項目的必備,在上面基本上很多類的源碼也能查到。
接著自己封裝了一個JasperReport類,而這個類可以實現導出各種格式的文件,代碼如下:
packagecommon.ireport;
importnet.sf.jasperreports.engine.*;
importnet.sf.jasperreports.engine.export.*;
importnet.sf.jasperreports.engine.export.JRRtfExporter;
importjava.util.List;
importjava.io.*;
import com.log.Logger;
/**
*IReport+JasperReport導出報表類介面
*<p>Title:導出報表類</p>
*<p>Description:</p>
*<p>Copyright:Copyright(c)2007</p>
*<font class=companyfont>
*CES
*</font>
*@author 野穀子
*@version 1.0.2007.02.14
*/
publicclassJasperReport{
privateLogger logger= newLogger("common.ireport.JasperReport");
/**CreatesanewinstanceofMyReport*/
publicJasperReport(){
}
/*
* 導出單個報表為rtf或word
* @param JasperPrint,OutputStream
* @ 頁面設置response.setContentType("application/msword");
* @ 頁面設置response.setHeader("Content-disposition","attachment;filename=fileName.doc");
* @ 頁面設置response.setContentLength(bytes.length);
*/
publicvoidexportReportToRTF(JasperPrint jasperPrint,OutputStreamout){
JRRtfExporter rtfExporter= newJRRtfExporter();
rtfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
rtfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
try{
rtfExporter.exportReport();
logger.debug("Genertate the RTF report ok! :"+ out);
} catch(JRException e) {
e.printStackTrace();
logger.error("Generate the RTF report file ERROR!");
}
}
/*
* 導出多個報表為rtf或word
* @param List,OutputStream
* @ 頁面設置response.setContentType("application/msword");
* @ 頁面設置response.setHeader("Content-disposition","attachment;filename=fileName.doc");
* @ 頁面設置response.setContentLength(bytes.length);
*/
(List jasperPrints,OutputStream out){
JRRtfExporter rtfExporter= newJRRtfExporter();
rtfExporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrints);
rtfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
try{
rtfExporter.exportReport();
logger.debug("Genertate the mutiply RTF report ok! :"+ out);
} catch(JRException e) {
e.printStackTrace();
logger.error("Generate the mutiply RTF report file ERROR!");
}
}
/*
* 導出單個報表為PDF
* @param JasperPrint,OutputStream
* @ 頁面設置response.setContentType("application/pdf");
* @ 頁面設置response.setHeader("Content-disposition","attachment;filename=fileName.pdf");
* @ 頁面設置response.setContentLength(bytes.length);
*/
publicvoidexportReportToPDF(JasperPrint jasperPrint,OutputStreamout){
JRPdfExporter pdfExporter = newJRPdfExporter();
pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
pdfExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
try{
pdfExporter.exportReport();
logger.debug("Genertate the PDF report ok! :"+ out);
} catch(JRException e) {
e.printStackTrace();
logger.error("Generate the PDF report file ERROR!");
}
}
/*
* 導出單個報表為XLS
* @param JasperPrint,OutputStream
* @ 頁面設置response.setContentType("application/vnd.ms-excel");
* @ 頁面設置response.setHeader("Content-disposition","attachment;filename=fileName.xls");
* @ 頁面設置response.setContentLength(bytes.length);
*/
publicvoidexportReportToXLS(JasperPrint jasperPrint,OutputStreamout){
JRXlsExporter xlsExporter= newJRXlsExporter();
xlsExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
xlsExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
xlsExporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);
try{
xlsExporter.exportReport();
logger.debug("Genertate the XLS report ok! :"+ out);
} catch(JRException e) {
e.printStackTrace();
logger.error("Generate the XLS report file ERROR!");
}
}
/*
* 導出單個報表為HTML
* @param JasperPrint,OutputStream
* @ 頁面設置response.setContentType("text/html");
* @ 頁面設置response.setHeader("Content-disposition","attachment;filename=fileName.html");
* @ 頁面設置response.setContentLength(bytes.length);
*/
publicvoidexportReportToHTML(JasperPrint jasperPrint,OutputStreamout){
JRHtmlExporter htmlExporter = newJRHtmlExporter();
htmlExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
htmlExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
htmlExporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
htmlExporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.FALSE);
try{
htmlExporter.exportReport();
logger.debug("Genertate the HTML report ok! :"+ out);
} catch(JRException e) {
e.printStackTrace();
logger.error("Generate the HTML report file ERROR!");
}
}
/*
* 導出單個報表為CSV
* @param JasperPrint,OutputStream
*/
publicvoidexportReportToCSV(JasperPrint jasperPrint,OutputStreamout){
JRCsvExporter csvExporter = newJRCsvExporter();
csvExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
csvExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
try{
csvExporter.exportReport();
logger.debug("Genertate the CSV report ok! :"+ out);
} catch(JRException e) {
e.printStackTrace();
logger.error("Generate the CSV report file ERROR!");
}
}
/*
* 導出單個報表為TXT
* @param JasperPrint,OutputStream
* @ 頁面設置response.setContentType("text/html");
* @ 頁面設置response.setHeader("Content-disposition","attachment;filename=fileName.txt");
* @ 頁面設置response.setContentLength(bytes.length);
*/
publicvoidexportReportToTXT(JasperPrint jasperPrint,OutputStreamout){
JRTextExporter txtExporter = newJRTextExporter();
txtExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
txtExporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
txtExporter.setParameter(JRTextExporterParameter.CHARACTER_WIDTH, newInteger(80));
txtExporter.setParameter(JRTextExporterParameter.CHARACTER_HEIGHT, newInteger(25));
try{
txtExporter.exportReport();
logger.debug("Genertate the TXT report ok! :"+ out);
} catch(JRException e) {
e.printStackTrace();
logger.error("Generate the TXT report file ERROR!");
}
}
/*
* 導出單個報表為XML
* @param JasperPrint,OutputStream
*/
publicvoidexportReportToXML(JasperPrint jasperPrint,OutputStreamout){
try{
JasperExportManager.exportReportToXmlStream(jasperPrint, out);
logger.debug("Genertate the XML report ok! :"+ out);
} catch(JRException e) {
e.printStackTrace();
logger.error("Generate the XML report file ERROR!");
}
}
}
然後寫了一個Control類用於封裝.jasper文件,並獲取其對象,代碼如下:
packagecommon.ireport;
importnet.sf.jasperreports.engine.*;
importnet.sf.jasperreports.engine.export.*;
importnet.sf.jasperreports.engine.export.JRRtfExporter;
importnet.sf.jasperreports.engine.util.*;
importnet.sf.jasperreports.view.*;
importjava.util.*;
importjava.util.List;
importjava.sql.*;
importjava.io.*;
import java.net.URL;
/**
*導出報表控制類*<p>Title:導出報表控制類</p>
*<p>Description:</p>
*<p>Copyright:Copyright(c)2007</p>
*<font class=companyfont>
*CES
*</font>
*@author 野穀子
*@version 1.0.2007.02.14
*/
publicclassJsperReportControl {
privateLogger logger= newLogger("common.ireport.JsperReportControl");
privateQuery query= newQuery();
//定義報表模版路徑
privateString PREFIX="/ireportFile/";
//定義後綴名
privateString SUFFIX=".jasper";
publicJsperReportControl(){
}
/*
* 取得報表模版的對象
* 單個參數的情況
* @param 報表名稱:strFileName
* @param 參數名稱:strParamName
* @param 參數值:strParamValue
* @return JasperPrint
*/
publicJasperPrint getJsperPrint(String strFileName,String strParamName,String strParamValue) throwsSQLException{
JasperPrint jasperPrint = null;
String strJasper= this.getClassPath() + PREFIX + strFileName + SUFFIX ;
Map params = newHashMap();
params.put(strParamName,strParamValue);
//定義數據源連接對象
Connection conn = null;
query.createConnection(CommonManage.CONN);
conn = query.getConnection();
try{
//用JasperFillManager類導入.jasper文件,參數和數據源
jasperPrint = JasperFillManager.fillReport(strJasper, params, conn);
try{
if(conn==null){
conn.close();
}
}catch(SQLException sqle){
logger.error("關閉資料庫連接錯誤"+sqle);
}
}catch(Exception e){
logger.error("getJsperPrint(String strFileName,String strParamName,String strParamValue) Error"+e);
}
returnjasperPrint;
}
/**
*在類中取得當前文件所在的相對路徑與絕對路徑
*
*@return String
*/
publicStringgetClassPath(){
StringstrClassName=getClass().getName();
StringstrPackageName="";
StringstrURL= "";
if(getClass().getPackage()!=null)
{
strPackageName=getClass().getPackage().getName();
}
//System.out.println("ClassName:"+strClassName);
//System.out.println("PackageName:"+strPackageName);
StringstrClassFileName="";
if(!"".equals(strPackageName))
{
strClassFileName=strClassName.substring(strPackageName.length()+1,strClassName.length());
}
else
{
strClassFileName=strClassName;
}
//System.out.println("ClassFileName:"+strClassFileName);
String strTempName = strClassFileName+".class";
try
{
URLurl=null;
url=getClass().getResource(strClassFileName+".class");
strURL=url.toString();
System.out.println(strURL);
logger.info("strURL="+strURL);
}
catch(Exceptionex)
{
ex.printStackTrace();
}
//取.jasper文件的絕對路徑
strURL= strURL.substring("file:".length(),strURL.length()-strTempName.length());
System.out.println("strURL="+strURL);
returnstrURL;
}
}
期間在取絕對路徑時出現了問題,在本機測試可以通過,但放在伺服器上報錯,原因是本機是windows系統,而伺服器是linux系統,到現在我覺得最大的原因是getClass().getResource()這個方法在linux系統上取不到資源的位置而報錯。
最後就是所寫的 jsp 頁面了 , 代碼如下:
<%@ page import="java.util.Vector"%>
<%@ page import="java.io.*" %>
<%@ page import="java.io.OutputStream" %>
<%@ page import="java.util.List"%>
<%@ page import="net.sf.jasperreports.engine.*" %>
<%@ page import="common.ireport.JsperReportControl"%>
<%@ page import="common.ireport.JasperReport"%>
<%
String strMode = WebUtil.getParam(request,"mode").equals("")?"":WebUtil.getParam(request,"mode");
JsperReportControl jsperReportControl = newJsperReportControl();
JasperReport jasperReport = newJasperReport();
strFileName1 ="quanlitySupervise_page1";
strFileName2 ="quanlitySupervise_page2";
strFileName3 ="quanlitySupervise_page3";
strFileName4 ="quanlitySupervise_page4";
strFileName5 ="quanlitySupervise_page5";
strFileName6 ="quanlitySupervise_page6";
strFileName7 ="quanlitySupervise_page7";
strFileName8 ="quanlitySupervise_page8";
String strParamName="ID";
String strParamValue=strProjectID;
ByteArrayOutputStream baos = newByteArrayOutputStream();
String strQueryConditionTmp="projectName="+strProjectName;
QueryCtrl queryCtrl = newQueryCtrl();
String str="";
if(strMode.equals("out")){
JasperPrint jasperPrint1= jsperReportControl.getJsperPrint(strFileName1,strParamName,strParamValue);
JasperPrint jasperPrint2= jsperReportControl.getJsperPrint(strFileName2,strParamName,strParamValue);
JasperPrint jasperPrint3= jsperReportControl.getJsperPrint(strFileName3,strParamName,strParamValue);
JasperPrint jasperPrint4= jsperReportControl.getJsperPrint(strFileName4,strParamName,strParamValue);
JasperPrint jasperPrint5= jsperReportControl.getJsperPrint(strFileName5,strParamName,strParamValue);
JasperPrint jasperPrint6= jsperReportControl.getJsperPrint(strFileName6,strParamName,strParamValue);
JasperPrint jasperPrint7= jsperReportControl.getJsperPrint(strFileName7,strParamName,strParamValue);
JasperPrint jasperPrint8= jsperReportControl.getJsperPrint(strFileName8,strParamName,strParamValue);
List reportlist = (List)newjava.util.ArrayList();
reportlist.add(jasperPrint1);
reportlist.add(jasperPrint2);
reportlist.add(jasperPrint3);
reportlist.add(jasperPrint4);
reportlist.add(jasperPrint5);
reportlist.add(jasperPrint6);
reportlist.add(jasperPrint7);
reportlist.add(jasperPrint8);
//導出單頁測試用
//jasperReport.exportReportToRTF(jasperPrint1,baos);
//整合多頁導出
jasperReport.exportReportListToRTF(reportlist,baos);
byte[] bytes;
bytes = baos.toByteArray();
response.setContentType("application/ms_word");
String strDocName ="attachment;filename="+strProjectID+".doc";
response.setHeader("Content-disposition",strDocName);
response.setContentLength(bytes.length);
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
}
}
%>
結尾:在本機測試通過了,但放於伺服器出現了錯誤: Can't connect to X11 window server using':0.0' as the value of the DISPLAY
而在 windows 系統中卻能正確運行,原因是程序調用了圖形界面的功能,而 windows 很好的支持圖形界面, linux 卻不能很好的支持,需要修改 linux 中的 DISPLAY 的變數:
下面有幾種方法:
1. 對於 tomcat 伺服器:找到腳本: catalina.sh ,
在 /usr/local/tomcat/bin/catalina.sh 中修改為
JAVA_OPTS="-Djava.awt.headless=true" 或者 CATALINA_OPTS="-Djava.awt.headless=true"
echo "Using CATALINA_BASE:$CATALINA_BASE"
echo "Using CATALINA_HOME:$CATALINA_HOME"
echo "Using CATALINA_TMPDIR:$CATALINA_TMPDIR"
echo "Using RUNJAVA:$_RUNJAVA"
echo "Using JAVA_OPTS:$JAVA_OPTS"
2 .對於伺服器中 oracle 自帶的 JSP server ,找到 jserv.properties 這個配置文件,在上面添加:
wrapper.env=DISPLAY=<SERVERNAME>:0
3 .或者用root身份執行一下xhost +命令,
第一種情況:DISPLAY在遠程資料庫中沒有正確定義,需要:
set DISPLAY=localComputer:0
export DISPLAY(取決於shell的不同而命令不同)
第二種情況:圖形界面的功能不能在遠程登陸的用戶中定義和使用,需要:
使用oracle用戶登錄xwindow:應用xhost +命令
哥們你看我說的對你有幫助嘛我就知道那麼多了