導航:首頁 > 編程語言 > javappt讀取

javappt讀取

發布時間:2022-08-31 13:57:41

『壹』 如何用java實現在指定窗口內打開PPT

Apache的poi是為java寫的解析office文件的庫,本身有解析ppt的功能,官方網址是http://poi.apache.org/,http://poi.apache.org/slideshow/是其ppt讀取組件。
我大致看了一下,它會把ppt中的文本解析成RichTextRun對象,大概是html格式的富文本,至於圖片貌似要另行獲取。總的來說能滿足你的要求。

『貳』 java讀取用戶上傳的jpg、pdf、doc、xls、ppt文件,將這些文件的二進制數據存儲到資料庫,或者文件形式存儲

一般文件不適合存儲到資料庫,最好用文件伺服器什麼的,簡單點可以存到本工程某個目錄下
上傳一般用form或者用插件比如jquery的uploadify,網上有示例非常簡單,action接收到文件後,直接new File(path) 到文件存儲目錄就好了

『叄』 如何通過JAVA 讀取.wps et及 dps文件格式的內容

下面是三個java例子,關於讀取wps/et/dps的方法

1.讀取wps(讀取文本): 通過流載入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();
}
}
}
}

2. 讀取et:直接載入et格式的表格文件,讀取數據

import com.spire.xls.*;

public class ExcelToText {
public static void main(String[] args) {
//載入et格式的表格文件
Workbook workbook = new Workbook();
workbook.loadFromFile("test.et");

//獲取工作表
Worksheet sheet = workbook.getWorksheets().get(0);

//獲取指定單元格中的文本數據
CellRange range = sheet.getCellRange("A1");
String text = range.getText().trim();
System.out.println(text);
}
}

3.讀取dps:直接載入dps格式的幻燈片文檔,讀取文本

import com.spire.presentation.IAutoShape;
import com.spire.presentation.ISlide;
import com.spire.presentation.ParagraphEx;
import com.spire.presentation.Presentation;
import java.io.FileWriter;

public class ExtractText {
public static void main(String[]args) throws Exception{
//載入測試文檔
Presentation ppt = new Presentation();
//ppt.loadFromFile("test.pptx");
ppt.loadFromFile("test.dps");

StringBuilder buffer = new StringBuilder();

//遍歷文檔中的幻燈片,提取文本
for (Object slide : ppt.getSlides())
{
for (Object shape : ((ISlide) slide).getShapes())
{
if (shape instanceof IAutoShape)
{
for (Object tp : ((IAutoShape) shape).getTextFrame().getParagraphs())
{
buffer.append(((ParagraphEx) tp).getText());
}
}
}
}
//保存到文本文件
FileWriter writer = new FileWriter("ExtractTextfromDPS.txt");
writer.write(buffer.toString());
writer.flush();
writer.close();
}
}

這里須在Java程序中導入spire.office.jar文件。

『肆』 apache poi獲取ppt全部內容和細化讀取的區別

有時候我們需要從Excel文件中讀取數據,或者我們為了商務或者財政的目的生成Excel格式的報表.Java沒有對操作Excel文件提供內在的支持,所以我們需要尋找開源的APIs.當我開始尋找操作Excel的APIs時候,大部分人建議使用JExcel或者Apache POI.

在深入研究後,我發現由於以下主要原因Apache POI是正確的選擇.還有些關於高級特性的原因,但是我們不深入太多細節.
1)Apache基金的支持.
2)JExcel不支持xlsx格式而POI既支持xls格式又支持xlsx格式.
3)Apache POI是基於流的處理,因此更適合大文件和要求更少的內存.
Apache POI對處理Excel文件提供了強大的支持,並且能處理xls和xlsx格式的電子表格.

關於Apache POI一些重要的地方:
1)Apache POI包含適合Excel97-2007(.xls文件)的HSSF實現.
2)Apache POI XSSF實現用來處理Excel2007文件(.xlsx).
3)Apache POI HSSF和XSSF提供了讀/寫/修改Excel表格的機制.
4)Apache POI提供了XSSF的一個擴展SXSSF用來處理非常大的Excel工作單元.SXSSF API需要更少的內存,因此當處理非常大的電子表格同時堆內存又有限時,很合適使用.
5)有兩種模式可供選擇--事件模式和用戶模式.事件模式要求更少的內存,因為用tokens來讀取Excel並處理.用戶模式更加面向對象並且容易使用,因此在我們的示例中使用用戶 模式.
6)Apache POI為額外的Excel特性提供了強大支持,例如處理公式,創建單元格樣式--顏色,邊框,字體,頭部,腳部,數據驗證,圖像,超鏈接等.

Apache POI的Maven依賴

[java] view plain
<span style="font-size:14px;"><dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10-FINAL</version>
</dependency></span>

Apache POI的當前版本是3.10-FINAL.如果你使用單獨的java應用,添加jars根據下面的圖片.

讀取Excel文件
假設我們有一個叫Sample.xlsx的Excel文件,裡面有兩個sheet並且下面圖片中的數據.我們想要讀取這個Excel文件並且創建Countries list.sheet1有些額外的數據,當我們解析時會忽略它.

我們的國家(Country)java bean如下:

Country.java

[java] view plain
package com.journaldev.excel.read;

public class Country {

private String name;
private String shortCode;

public Country(String n, String c){
this.name=n;
this.shortCode=c;
}

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getShortCode() {
return shortCode;
}
public void setShortCode(String shortCode) {
this.shortCode = shortCode;
}

@Override
public String toString(){
return name + "::" + shortCode;
}

}

讀取Excel文件並創建Countries list代碼如下:

ReadExcelFileToList.java

[java] view plain
package com.journaldev.excel.read;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ReadExcelFileToList {

public static List<Country> readExcelData(String fileName) {
List<Country> countriesList = new ArrayList<Country>();

try {
//Create the input stream from the xlsx/xls file
FileInputStream fis = new FileInputStream(fileName);

//Create Workbook instance for xlsx/xls file input stream
Workbook workbook = null;
if(fileName.toLowerCase().endsWith("xlsx")){
workbook = new XSSFWorkbook(fis);
}else if(fileName.toLowerCase().endsWith("xls")){
workbook = new HSSFWorkbook(fis);
}

//Get the number of sheets in the xlsx file
int numberOfSheets = workbook.getNumberOfSheets();

//loop through each of the sheets
for(int i=0; i < numberOfSheets; i++){

//Get the nth sheet from the workbook
Sheet sheet = workbook.getSheetAt(i);

//every sheet has rows, iterate over them
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext())
{
String name = "";
String shortCode = "";

//Get the row object
Row row = rowIterator.next();

//Every row has columns, get the column iterator and iterate over them
Iterator<Cell> cellIterator = row.cellIterator();

while (cellIterator.hasNext())
{
//Get the Cell object
Cell cell = cellIterator.next();

//check the cell type and process accordingly
switch(cell.getCellType()){
case Cell.CELL_TYPE_STRING:
if(shortCode.equalsIgnoreCase("")){
shortCode = cell.getStringCellValue().trim();
}else if(name.equalsIgnoreCase("")){
//2nd column
name = cell.getStringCellValue().trim();
}else{
//random data, leave it
System.out.println("Random data::"+cell.getStringCellValue());
}
break;
case Cell.CELL_TYPE_NUMERIC:
System.out.println("Random data::"+cell.getNumericCellValue());
}
} //end of cell iterator
Country c = new Country(name, shortCode);
countriesList.add(c);
} //end of rows iterator

} //end of sheets for loop

//close file input stream
fis.close();

} catch (IOException e) {
e.printStackTrace();
}

return countriesList;
}

public static void main(String args[]){
List<Country> list = readExcelData("Sample.xlsx");
System.out.println("Country List\n"+list);
}

}

這個程序很容易明白,主要步驟如下:
1)根據文件類型(.xls與.xlsx)創建Workbook實例,xlsx用XSSFWorkbook,xls用HSSFWorkbook.我們可以基於文件名字使用工 廠模式創建一個包裝類來創建Workbook實例.
2)使用Workbook getNumberOfSheets()來獲取sheet的數量,然後循環解析每一個sheet.使用getSheetAt(int i)方法獲取 Sheet實例.
3)獲取Row和Cell迭代器來獲取每一個Cell對象.Apache POI在這里使用了迭代器模式.
4)使用switch-case根據Cell的類型來處理它.

『伍』 java讀取doc,pdf問題。

PDFBox是一個開源的對pdf文件進行操作的庫。 PDFBox-0.7.3.jar加入classpath。同時FontBox1.0.jar加入classpath,否則報錯



importjava.io.FileInputStream;
importjava.io.FileNotFoundException;
importjava.io.IOException;

importorg.pdfbox.pdfparser.PDFParser;
importorg.pdfbox.pdmodel.PDDocument;
importorg.pdfbox.util.PDFTextStripper;

publicclassPdfReader{
/**
*.
*.
*2008-2-25
*@parampdfFilePathfilepath
*@returnalltextinthepdffile
*/
(StringpdfFilePath)
{
Stringresult=null;
FileInputStreamis=null;
PDDocumentdocument=null;
try{
is=newFileInputStream(pdfFilePath);
PDFParserparser=newPDFParser(is);
parser.parse();
document=parser.getPDDocument();
PDFTextStripperstripper=newPDFTextStripper();
result=stripper.getText(document);
}catch(FileNotFoundExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}finally{
if(is!=null){
try{
is.close();
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
if(document!=null){
try{
document.close();
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}
returnresult;
}
publicstaticvoidmain(String[]args)
{
Stringstr=PdfReader.getTextFromPDF("C:\Read.pdf");
System.out.println(str);

}
}

代碼2:

importjava.io.File;
importjava.io.FileOutputStream;
importjava.io.OutputStreamWriter;
importjava.io.Writer;
importjava.net.MalformedURLException;
importjava.net.URL;
importorg.pdfbox.pdmodel.PDDocument;
importorg.pdfbox.util.PDFTextStripper;
publicclassPDFReader{
publicvoidreadFdf(Stringfile)throwsException{

booleansort=false;

StringpdfFile=file;

StringtextFile=null;

Stringencoding="UTF-8";

intstartPage=1;

intendPage=Integer.MAX_VALUE;

Writeroutput=null;

PDDocumentdocument=null;
try{
try{
//首先當作一個URL來裝載文件,如果得到異常再從本地文件系統//去裝載文件
URLurl=newURL(pdfFile);
//注意參數已不是以前版本中的URL.而是File。
document=PDDocument.load(pdfFile);
//獲取PDF的文件名
StringfileName=url.getFile();
//以原來PDF的名稱來命名新產生的txt文件
if(fileName.length()>4){
FileoutputFile=newFile(fileName.substring(0,fileName
.length()-4)
+".txt");
textFile=outputFile.getName();
}
}catch(MalformedURLExceptione){
//如果作為URL裝載得到異常則從文件系統裝載
//注意參數已不是以前版本中的URL.而是File。
document=PDDocument.load(pdfFile);
if(pdfFile.length()>4){
textFile=pdfFile.substring(0,pdfFile.length()-4)
+".txt";
}
}

output=newOutputStreamWriter(newFileOutputStream(textFile),
encoding);

PDFTextStripperstripper=null;
stripper=newPDFTextStripper();
//設置是否排序
stripper.setSortByPosition(sort);
//設置起始頁
stripper.setStartPage(startPage);
//設置結束頁
stripper.setEndPage(endPage);
//調用PDFTextStripper的writeText提取並輸出文本
stripper.writeText(document,output);
}finally{
if(output!=null){
//關閉輸出流
output.close();
}
if(document!=null){
//關閉PDFDocument
document.close();
}
}
}
/**
*@paramargs
*/
publicstaticvoidmain(String[]args){
//TODOAuto-generatedmethodstub
PDFReaderpdfReader=newPDFReader();
try{
//取得E盤下的SpringGuide.pdf的內容
pdfReader.readFdf("C:\Read.pdf");
}catch(Exceptione){
e.printStackTrace();
}
}
}

2、抽取支持中文的pdf文件-xpdf
xpdf是一個開源項目,我們可以調用他的本地方法來實現抽取中文pdf文件。
http://www.java-cn.com/technology/tech_downs/1880_004.zip
補丁包:
http://www.java-cn.com/technology/tech_downs/1880_005.zip
按照readme放好中文的patch,就可以開始寫調用本地方法的java程序了。
下面是一個如何調用的例子:

importjava.io.*;
/**
*<p>Title:pdfextraction</p>
*<p>Description:email:[email protected]</p>
*<p>Copyright:MatrixCopyright(c)2003</p>
*<p>Company:Matrix.org.cn</p>
*@authorchris
*@version1.0,
*/


publicclassPdfWin{
publicPdfWin(){
}
publicstaticvoidmain(Stringargs[])throwsException
{
StringPATH_TO_XPDF="C:ProgramFilesxpdfpdftotext.exe";
Stringfilename="c:a.pdf";
String[]cmd=newString[]{PATH_TO_XPDF,"-enc","UTF-8","-q",filename,"-"};
Processp=Runtime.getRuntime().exec(cmd);
BufferedInputStreambis=newBufferedInputStream(p.getInputStream());
InputStreamReaderreader=newInputStreamReader(bis,"UTF-8");
StringWriterout=newStringWriter();
char[]buf=newchar[10000];
intlen;
while((len=reader.read(buf))>=0){
//out.write(buf,0,len);
System.out.println("thelengthis"+len);
}
reader.close();
Stringts=newString(buf);
System.out.println("thestris"+ts);
}
}

『陸』 java如何讀取ppsx文檔

要完成如題所述的操作,需要將「ppsx」文件另存為「ppt」文件,方法具體如下: 第一步:啟動PowerPoint軟體,文件-打開,如圖,打開「打開」對話框,選取ppsx文件,單擊確定按鈕。 第二步:文件-另存為,如圖,打開「另存為」對話框,設置文件類型為「ppt.

『柒』 jsp讀取word,ppt,pdf

把PDF文件寫入response流裡面就可以了!
方法有很多,這里給個獨立又簡單的例子:

Java代碼
1.package com.zhaipuhong.j2se.pdf;
2.
3.import java.io.IOException;
4.import java.util.Date;
5.
6.import javax.servlet.ServletException;
7.import javax.servlet.http.HttpServlet;
8.import javax.servlet.http.HttpServletRequest;
9.import javax.servlet.http.HttpServletResponse;
10.
11.import com.lowagie.text.Document;
12.import com.lowagie.text.DocumentException;
13.import com.lowagie.text.Paragraph;
14.import com.lowagie.text.pdf.PdfWriter;
15.import com.lowagie.text.pdf.BaseFont;
16.import com.lowagie.text.pdf.PdfPTable;
17.import com.lowagie.text.pdf.PdfPCell;
18.import java.awt.Color;
19.
20.public class PdfServlet extends HttpServlet {
21.
22. private static final long serialVersionUID = -6033026500372479591L;
23.
24. public void doGet (HttpServletRequest request, HttpServletResponse response)
25. throws IOException, ServletException {
26.
27. // step 1 建立文檔對象
28. Document document = new Document();
29. try {
30. //設置文檔相應類型
31. response.setContentType("application/pdf");
32. PdfWriter.getInstance(document, response.getOutputStream());
33.
34.
35. // step 3 打開文檔
36. document.open();
37. //支持中文
38. BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
39. com.lowagie.text.Font FontChinese = new com.lowagie.text.Font(bfChinese, 12, com.lowagie.text.Font.NORMAL);
40. Paragraph pragraph=new Paragraph("你好", FontChinese);
41.
42.
43. // step 4 向文檔中添加內容
44. document.add(pragraph);
45. document.add(new Paragraph(" Hello World !"));
46. document.add(new Paragraph("Date 時間"+new Date().toString()));
47. document.add(new Paragraph(new Date().toString()));
48. document.add(new Paragraph(new Date().toString()));
49.
50.
51.
52. PdfPTable table = new PdfPTable(3);
53. PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
54. cell.setColspan(3);
55. table.addCell(cell);
56. table.addCell("1.1");
57. table.addCell("2.1");
58. table.addCell("3.1");
59. table.addCell("1.2");
60. table.addCell("2.2");
61. table.addCell("3.2");
62. cell = new PdfPCell(new Paragraph("cell test1"));
63. cell.setBorderColor(new Color(255, 0, 0));
64. table.addCell(cell);
65. cell = new PdfPCell(new Paragraph("cell test2"));
66. cell.setColspan(2);
67. cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
68. table.addCell(cell);
69. document.add(table);
70.
71. }catch(DocumentException de) {
72. de.printStackTrace();
73. System.err.println("document: " + de.getMessage());
74. }
75.
76. // step 5: 關閉文檔對象
77. document.close();
78. }
79.
80. //支持中文
81. public Paragraph getChineseString(String chineseString){
82. Paragraph pragraph=null;
83. BaseFont bfChinese = null;
84. try {
85. bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",
86. BaseFont.NOT_EMBEDDED);
87. com.lowagie.text.Font FontChinese = new com.lowagie.text.Font(bfChinese,
88. 12, com.lowagie.text.Font.NORMAL);
89. pragraph = new Paragraph(chineseString, FontChinese);
90. }
91. catch (Exception ex) {
92. ex.printStackTrace();
93. }
94. return pragraph;
95. }
96.}

『捌』 java 讀取pdf, word, excel, ppt文檔的內容,下了POI包,但是不知道怎麼用,剛學java,求告訴一下怎麼辦

讀取pdf需要下載pdfbox:
http://pdfbox.apache.org/
新建一個Project,然後把POI的src導入到該工程。
【How to create an Eclipse Project 】你可以參考:
http://mail-archives.apache.org/mod_mbox/poi-dev/201204.mbox/%3cCAPt+24QbEryNixQFuPhEsKx16oHcn_h5xEa0x9uMSEVYLe-fPw@mail.gmail.com%3e

『玖』 java調用dll操作ppt

你這個操作可以簡化為復制你這個ppt文件嘛,然後將ppt復制後的文件名稱修改了下,不調用外部dll也可以實現吧
給你推薦兩種方法:
方法1:使用Java執行cmd命令操作
try {
Runtime.getRuntime().exec("這里寫dos命令");
} catch (IOException e) {
e.printStackTrace();
}

復制文件的cmd命令是[ 文件1路徑 文件2路徑]
例如復制c盤上的test.ppt 到 c盤上的test1.ppt
命令: c:\test.ppt c:\test1.ppt
在Java中就是 c:\\test.ppt c:\\test1.ppt或者 c:/test.ppt c:/test1.ppt

方法2:使用Java io復制文件

import java.io.*;
public class CopyAll {
public void Dir(File from, File to) {
if (!to.exists()) {
to.mkdirs();
}
File[] files = from.listFiles();
for (int i = 0; i < files.length; i++) {
File file1 = files[i];
File file2 = new File(to.getPath() + File.separator
+ files[i].getName());
if (!file1.isDirectory()) {
File(file1, file2);
} else {
Dir(file1, file2);
}
}
}
public void File(File src, File dest) {
try {
System.out.println(src.getAbsoluteFile() + " -> "
+ dest.getAbsoluteFile());
FileInputStream in = new FileInputStream(src);
FileOutputStream out = new FileOutputStream(dest);
byte[] buffer = new byte[1024];
while (in.read(buffer) != -1) {
out.write(buffer);
}
out.close();
in.close();
System.out.println("文件拷貝成功");
} catch (Exception e) {
System.out.println("文件拷貝失敗");
}
}
public static void main(String[] args) {
CopyAll t = new CopyAll();
t.Dir(new File("原文件路徑"), new File("要復制文件路徑"));
}
}

哦 不好意思,跑題了
Java是可以利用Java的JNI(Java native interface)Java本地介面調用dll的,但是這個dll與一般的dll不同,定義要遵循一些規則,所以Java是不能操作一般的dll。還有就是你得懂C或C++才能寫出Java可調用的dll,我也只會操作helloword等簡單的dll,還有一般Java操作word、excel、ppt這些文件都有開源項目,你可以到網路 Google上去搜索一下
例如:http://www.javayou.com/diary/1637

閱讀全文

與javappt讀取相關的資料

熱點內容
日本電影叫什麼魚的名字 瀏覽:663
找書pdf 瀏覽:392
高水平應屆程序員有前途嗎 瀏覽:79
哪個視頻網站可以投屏還免費 瀏覽:283
好看愛情網 瀏覽:304
泰國電影女主叫小草 瀏覽:543
模具設計的命令如何用 瀏覽:990
華為雲桌面伺服器多少錢一台 瀏覽:271
木工數控刀具路徑編程 瀏覽:275
用電腦看高清電影在哪裡看 瀏覽:242
老外從牆壁穿越的電影 瀏覽:813
下人電影完整版下載 瀏覽:589
雲伺服器下載服務 瀏覽:241
pdf如何插入頁碼 瀏覽:637
ps選擇命令大全 瀏覽:826
qq聊天記錄恢復文件夾 瀏覽:646
電腦公共盤加密碼 瀏覽:459
韓國電影兩個字 瀏覽:971
鴻蒙系統怎麼給App加速 瀏覽:190