在本文中,我们将带你了解怎样给Word2007文档图片加上解说词在这篇文章中,我们将为您详细介绍怎样给Word2007文档图片加上解说词的方方面面,并解答如何给word中图片加说明文字常见的疑惑,同时
在本文中,我们将带你了解怎样给Word2007文档图片加上解说词在这篇文章中,我们将为您详细介绍怎样给Word2007文档图片加上解说词的方方面面,并解答如何给word中图片加说明文字常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的c# – Visual Studio 2010中的Word 2007文档、Java 解析 word2007 和 Excel2007、PHPWord解决中文乱码并导出生成Word2007(docx)格式文档、POI 将Excle2003,Excle2007,word2003,word2007转换为html。
本文目录一览:- 怎样给Word2007文档图片加上解说词(如何给word中图片加说明文字)
- c# – Visual Studio 2010中的Word 2007文档
- Java 解析 word2007 和 Excel2007
- PHPWord解决中文乱码并导出生成Word2007(docx)格式文档
- POI 将Excle2003,Excle2007,word2003,word2007转换为html
怎样给Word2007文档图片加上解说词(如何给word中图片加说明文字)
1.添加自动编号的题注。例如为文档中的一幅图片添加;图1:OfficeBa”解说词。操作步骤:单击图片以选中它,单击;引用”-;插入题注”,在弹出来的;题注”对话框中单击;新建标签”,在;标签”下的框中键入;图”字,单击;确定”按钮,在;图1”后键入;OfficeBa”,最后单击;确定”按钮即可。
小提示与键入文本不同,插入题注中的编号是Word2007自动加上的,它以域的形式存在。如果题注看上去类似于 {SEQTable\*ARABIC},则表明Word显示的是域代码而不是域结果。要查看域结果,请按Alt+F9键,也可以右键单击域代码,选择;切换域代码”。也正是因为题注编号以域的形式存在,所以以后对题注执行了添加、删除或移动操作,可以一次更新所有题注编号,非常方便。2.利用文本框添加标签。例如给图片中的角标上度数。 操作步骤:首先单击;插入”-;文本框”,选择;绘制文本框”,然后拖动鼠标在对象上绘制一个文本框,并键入;”。单击以选中文本框,将鼠标指针移动到文本框的边框,然后单击右击,选择;设置文本框格式”。单击;颜色与线条”选项,单击;颜色”后的方框,选择;无颜色”。将;透明度”滑块拖到最右边。单击;确定”按钮,在保持文本框选中的状态下,使用Ctrl+方向键将文本框调整得到最佳的位置。
小提示将某列单元格的数据设置为日期类型的方法为:选中该列单元格,右击,选择;设置单元格格式”,切换到;数字”选项卡,在分类下选中;日期”,单击;确定”。
3.给图片加上会话气泡。例如加个云形标注框,可以令图片增色不少。
操作步骤:单击;插入”-;形状”-;云形标注”,在图片上拖动鼠标画出一个气泡框,单击该框即可输入文字。
小提示这个云形标注框与文本框类似,在单击选中它之后,拖动尺寸控点即可改变其大小,拖动移动控点可移动其位置,拖动自由旋转控点可随意旋转标注框的方向,拖动指向控点可改变标注框引线的指向。而且,在保持标注框选中的状态下,使用Ctrl+方向键可将标注框调整到最恰当的位置.
c# – Visual Studio 2010中的Word 2007文档
我要做的是在我的C#应用程序中填入一个包含信息的报告类型文档,然后输出最终的.docx.这是否可以使用此功能,我该如何去做?
解决方法
它听起来像你想要的是Open XML SDK 2.0.这将提供创建Word(和其他Office)文档的完全访问权限,而无需Word程序或VSTO要求(VSTO运行时,主要Interop等)的程序或在创建它们的操作系统上. OpenXML SDK上有大量信息 – 一个很好的起点是http://www.openxmldeveloper.org.另一个是How-To视频.
Java 解析 word2007 和 Excel2007

package com.test;
/**
* 需要的jar包:
* poi-3.0.2-FINAL-20080204.jar
* poi-contrib-3.0.2-FINAL-20080204.jar
* poi-scratchpad-3.0.2-FINAL-20080204.jar
* poi-3.5-beta6-20090622.jar
* geronimo-stax-api_1.0_spec-1.0.jar
* ooxml-schemas-1.0.jar
* openxml4j-bin-beta.jar
* poi-ooxml-3.5-beta6-20090622.jar
* xmlbeans-2.3.0.jar
* dom4j-1.6.1.jar
*/
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.poi.POIXMLDocument;
import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.xmlbeans.XmlException;
public class WordAndExcelExtractor {
public static void main(String[] args){
try{
String wordFile = "D:/松山血战.docx";
String wordText2007 = WordAndExcelExtractor.extractTextFromDOC2007(wordFile);
System.out.println("wordText2007======="+wordText2007);
InputStream is = new FileInputStream("D:/XXX研发中心技术岗位职位需求.xls");
String excelText = WordAndExcelExtractor.extractTextFromXLS(is);
System.out.println("text2003==========" + excelText);
String excelFile = "D:/Hello2007.xlsx";
String excelText2007 = WordAndExcelExtractor.extractTextFromXLS2007(excelFile);
System.out.println("excelText2007==========" + excelText2007);
}catch(Exception e ){
e.printStackTrace();
}
}
/**
* @Method: extractTextFromDOCX
* @Description: 从word 2003文档中提取纯文本
*
* @param
* @return String
* @throws
*/
public static String extractTextFromDOC(InputStream is) throws IOException {
WordExtractor ex = new WordExtractor(is); //is是WORD文件的InputStream
return ex.getText();
}
/**
* @Method: extractTextFromDOCX
* @Description: 从word 2007文档中提取纯文本
*
* @param
* @return String
* @throws
*/
public static String extractTextFromDOC2007(String fileName) throws IOException, OpenXML4JException, XmlException {
OPCPackage opcPackage = POIXMLDocument.openPackage(fileName);
POIXMLTextExtractor ex = new XWPFWordExtractor(opcPackage);
return ex.getText();
}
/**
* @Method: extractTextFromXLS
* @Description: 从excel 2003文档中提取纯文本
*
* @param
* @return String
* @throws
*/
@SuppressWarnings("deprecation")
private static String extractTextFromXLS(InputStream is)
throws IOException {
StringBuffer content = new StringBuffer();
HSSFWorkbook workbook = new HSSFWorkbook(is); //创建对Excel工作簿文件的引用
for (int numSheets = 0; numSheets < workbook.getNumberOfSheets(); numSheets++) {
if (null != workbook.getSheetAt(numSheets)) {
HSSFSheet aSheet = workbook.getSheetAt(numSheets); //获得一个sheet
for (int rowNumOfSheet = 0; rowNumOfSheet <= aSheet.getLastRowNum(); rowNumOfSheet++) {
if (null != aSheet.getRow(rowNumOfSheet)) {
HSSFRow aRow = aSheet.getRow(rowNumOfSheet); //获得一行
for (short cellNumOfRow = 0; cellNumOfRow <= aRow.getLastCellNum(); cellNumOfRow++) {
if (null != aRow.getCell(cellNumOfRow)) {
HSSFCell aCell = aRow.getCell(cellNumOfRow); //获得列值
if(aCell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
content.append(aCell.getNumericCellValue());
}else if(aCell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN){
content.append(aCell.getBooleanCellValue());
}else {
content.append(aCell.getStringCellValue());
}
}
}
}
}
}
}
return content.toString();
}
/**
* @Method: extractTextFromXLS2007
* @Description: 从excel 2007文档中提取纯文本
*
* @param
* @return String
* @throws
*/
private static String extractTextFromXLS2007(String fileName) throws Exception{
StringBuffer content = new StringBuffer();
//构造 XSSFWorkbook 对象,strPath 传入文件路径
XSSFWorkbook xwb = new XSSFWorkbook(fileName);
//循环工作表Sheet
for(int numSheet = 0; numSheet < xwb.getNumberOfSheets(); numSheet++){
XSSFSheet xSheet = xwb.getSheetAt(numSheet);
if(xSheet == null){
continue;
}
//循环行Row
for(int rowNum = 0; rowNum <= xSheet.getLastRowNum(); rowNum++){
XSSFRow xRow = xSheet.getRow(rowNum);
if(xRow == null){
continue;
}
//循环列Cell
for(int cellNum = 0; cellNum <= xRow.getLastCellNum(); cellNum++){
XSSFCell xCell = xRow.getCell(cellNum);
if(xCell == null){
continue;
}
if(xCell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN){
content.append(xCell.getBooleanCellValue());
}else if(xCell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC){
content.append(xCell.getNumericCellValue());
}else{
content.append(xCell.getStringCellValue());
}
}
}
}
return content.toString();
}
}
转载自:
http://archive.cnblogs.com/a/1759383/PHPWord解决中文乱码并导出生成Word2007(docx)格式文档
最近一个项目开发要用到PHP技术导出Word文档,比较了几种方案,首先是使用Microsoft Office自 [] Related posts: 主机域名www的自适应301重定向方法 ASP/VBScript动态创建属性对象的工厂类(DynamicObject) ASP/VBScript中CHR(0)的由来以及带来的安全问题 原
最近一个项目开发要用到PHP技术导出Word文档,比较了几种方案,首先是使用Microsoft Office自 […]
Related posts:
- 主机域名www的自适应301重定向方法
- ASP/VBScript动态创建属性对象的工厂类(DynamicObject)
- ASP/VBScript中CHR(0)的由来以及带来的安全问题
原文地址:PHPWord解决中文乱码并导出生成Word2007(docx)格式文档, 感谢原作者分享。
POI 将Excle2003,Excle2007,word2003,word2007转换为html
上一篇是写了关于解析ppt,这一篇是关于Excle,Word的,其实用poi解析excle是非常好用的,参考了网上大神的东西,自己添加修改了些东西,都是写代码的苦命兄弟,拿出来共同参考下,有意见大家指正。遇到的问题是,如果用json将这些html代码返回的页面是不行的,因为json不支持html格式输出,折衷的办法是通过encodeURI编码,然后DecodeURI解码,但是全篇解码会有问题,有些字符如“=”,“;”等无法解析完全。所以不太建议用json,如果非用不可,最好手动解码(一听就知道是个很痛苦的事情),但还是会让html有瑕疵
package com.ysy.officeRead.controller;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.util.List;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.poi.hssf.converter.ExcelToHtmlConverter;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.converter.PicturesManager;
import org.apache.poi.hwpf.converter.WordToHtmlConverter;
import org.apache.poi.hwpf.usermodel.Picture;
import org.apache.poi.hwpf.usermodel.PictureType;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.converter.core.BasicURIResolver;
import org.apache.poi.xwpf.converter.core.FileImageExtractor;
import org.apache.poi.xwpf.converter.xhtml.XHTMLConverter;
import org.apache.poi.xwpf.converter.xhtml.XHTMLOptions;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.w3c.dom.Document;
public class OfficeBeRead {
/**
*url:标示上传文件在服务器本地的全路径,用来创建图片储存文件夹,使用uuID作为文件夹名称,挺恶心的事情
*projectPath: 文件在服务器上的路径
*/
public String poiWord2003ToHtml(String url, String projectPath) {
String pathString = url.substring(0, url.lastIndexOf("."));
String proString2 = projectPath.substring(0, projectPath.lastIndexOf("."))+"/";
String file = "1.doc";
String content = "";
//创建文件夹
try {
InputStream inputStream = new FileInputStream(url);
HWPFDocument worDocument = new HWPFDocument(inputStream);
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(DocumentBuilderFactory
.newInstance().newDocumentBuilder().newDocument());
wordToHtmlConverter.setPicturesManager(new PicturesManager() {
public String savePicture(byte[] content, PictureType pictureType, String suggestedName,
float widthInches, float heightInches) {
// TODO Auto-generated method stub
return suggestedName;
}
});
wordToHtmlConverter.processDocument(worDocument);
List pics = worDocument.getPicturesTable().getAllPictures();
if(pics!=null){
for (int i = 0; i < pics.size(); i++) {
Picture picture = (Picture) pics.get(i);
File file2 = new File(pathString,picture.suggestFullFileName());
if(!file2.exists()&&!file2.isDirectory()){
file2.getParentFile().mkdirs();
file2.createNewFile();
}
picture.writeImageContent(new FileOutputStream(pathString+"/"+picture.suggestFullFileName()));
}
}
Document htmlDocument = wordToHtmlConverter.getDocument();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DOMSource domSource = new DOMSource(htmlDocument);
StreamResult streamResult = new StreamResult(outputStream);
TransformerFactory tfFactory = TransformerFactory.newInstance();
Transformer serializer = tfFactory.newTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "utf-8");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(OutputKeys.METHOD, "html");
serializer.transform(domSource, streamResult);
outputStream.close();
content = new String(outputStream.toByteArray());
//图片路径替换
FileUtils.write(new File(pathString, "1.html"), content, "utf-8");
content = replaceAllStr(content, proString2);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return content;
}
/**
* url为文件上传后所在路径
* projectPath 为文件所在项目下的访问路径
*/
public String poiWord2007ToHtml(String url,String projectPath){
String sourceFileNameString = url; //目标文件路径
String imagePathString = url.substring(0, url.lastIndexOf("."));
String targetFileNameString = imagePathString+"1.html";
String proString2 = projectPath.substring(0, projectPath.lastIndexOf("."))+"/";
String out = "";
FileOutputStream outputStream = null;
OutputStreamWriter outputStreamWriter = null;
try {
XWPFDocument document = new XWPFDocument(new FileInputStream(sourceFileNameString));
XHTMLOptions options = XHTMLOptions.create();
//存放图片的文件夹
options.setExtractor(new FileImageExtractor(new File(imagePathString)));
//html中图片的路径
options.URIResolver(new BasicURIResolver("/"));
File file2 = new File(targetFileNameString);
if(!file2.exists()&&!file2.isDirectory()){
file2.getParentFile().mkdirs();
file2.createNewFile();
}
outputStream = new FileOutputStream(targetFileNameString);
outputStreamWriter = new OutputStreamWriter(outputStream);
XHTMLConverter xhtmlConverter = (XHTMLConverter) XHTMLConverter.getInstance();
xhtmlConverter.convert(document, outputStreamWriter, options);
FileInputStream file = new FileInputStream( new File(targetFileNameString));
// size 为字串的长度 ,这里一次性读完
int size=file.available();
byte[] buffer=new byte[size];
file.read(buffer);
file.close();
out=new String(buffer);
//这是用来解决生成的汉字是Uncio十进制码的
out = StringEscapeUtils.unescapeHtml(out);
System.out.println(out);
out = replaceAllStr(out, proString2);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}finally{
if(outputStream != null){
try {
outputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(outputStreamWriter != null){
try {
outputStreamWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return out;
}
/* public static void main(String[] args) {
System.out.println(new OfficeBeRead().poiWord2003ToHtml());
}*/
/**
*替换字符串中指定字符位置添加指定的字符串
*
*在此用来替换图片源路径
*
*/
public String replaceAllStr(String content,String imgurl){
String[] ss = content.split("<img src="+"\"");
String sssString = "";
if (ss.length>1) {
for (int i = 0; i < ss.length-1; i++) {
sssString = sssString+ss[i]+"<img src="+"\""+imgurl;
}
sssString = sssString + ss[ss.length-1];
}
return sssString;
}
/**
*poi将Excel转换为html
*该方法无法解析图片
*
*/
public String PoiExcel2003ToHtml(String url,String projectPath){
File excelFile = new File(url);
InputStream iStream = null;
FileOutputStream outputStream = null;
StringWriter writer = null;
String imagePathString = url.substring(0, url.lastIndexOf("."));
String htmlFile = imagePathString+"1.html";
File htmlfile2 = new File(htmlFile);
File filep = new File(htmlfile2.getParent());
String content = "";
try {
if(excelFile.exists()){
if(!filep.exists()){
filep.mkdirs();
}
iStream = new FileInputStream(excelFile); //初始化文件
HSSFWorkbook workbook = new HSSFWorkbook(iStream);
ExcelToHtmlConverter converter = new ExcelToHtmlConverter(DocumentBuilderFactory
.newInstance().newDocumentBuilder().newDocument());
converter.processWorkbook(workbook);
writer = new StringWriter();
Transformer serializer = TransformerFactory.newInstance().newTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(OutputKeys.METHOD, "html");
serializer.transform(
new DOMSource(converter.getDocument()),
new StreamResult(writer));
outputStream = new FileOutputStream(htmlFile);
outputStream.write(writer.toString().getBytes("UTF-8"));
FileInputStream fis = new FileInputStream(htmlfile2); //获取html文件输入流
int size = fis.available();
byte[] buffer=new byte[size];
fis.read(buffer);
fis.close();
content = new String(buffer);
System.out.println(content);
outputStream.flush();
outputStream.close();
writer.close();
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} finally{
if(iStream != null){
try {
iStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(outputStream != null){
try {
outputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(writer!=null){
try {
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return content;
}
/**
* POI 解析Excel2007版,生成HTML
* @param fileName 文件(含地址)
* @return 解析出来的HTML页面String
*/
public String PoiExcel2007ToHtml(String url,String projectPath){
StringBuffer content = new StringBuffer();
XSSFWorkbook xwb = null;
try{
// 构造 XSSFWorkbook 对象,strPath 传入文件路径
xwb = new XSSFWorkbook(url);
content.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><title>Parse Excel With POI</title></head><body>");
// 循环工作表Sheet
for (int numSheet = 0; numSheet < xwb.getNumberOfSheets(); numSheet++) {
XSSFSheet xSheet = xwb.getSheetAt(numSheet);
if (xSheet == null) {
continue;
}
content.append("<h3 valign=''middle'' align=''center''>"+xSheet.getSheetName()+"</h3>");
content.append("<table valign=''middle'' align=''center'' border=1 cellspacing=0 cellpadding=1>");
// 循环行Row
for (int rowNum = 0; rowNum <= xSheet.getLastRowNum(); rowNum++) {
XSSFRow xRow = xSheet.getRow(rowNum);
if (xRow == null) {
continue;
}
content.append("<tr align=''middle''>");
// 循环列Cell
for (int cellNum = 0; cellNum <= xRow.getLastCellNum(); cellNum++) {
XSSFCell xCell = xRow.getCell(cellNum);
if (xCell == null || "".equals(xCell)) {
content.append("<td>").append(" ").append("</td>");
}else if (xCell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) {
content.append("<td>").append(" ").append(xCell.getBooleanCellValue()).append("</td>");
} else if (xCell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
content.append("<td>").append(" ").append(this.doubleToString(xCell.getNumericCellValue())).append("</td>");
} else{
content.append("<td>").append(" ").append(xCell.getStringCellValue()).append("</td>");
}
}
content.append("</tr>");
}
content.append("</table>");
}
content.append("</body></html>");
}catch(Exception e){
e.printStackTrace();
System.out.println("POI解析Excel2007错误");
}
return content.toString();
}
/**
* change double variable into string type
* @param d
* @return
*/
public String doubleToString(double d){
String str = Double.valueOf(d).toString();
String temp = str;
String result = "";
if(str.indexOf("E")>2)
result = str.substring(0,1) + temp.substring(2, str.indexOf("E"));
else{
if(str.indexOf(".0")>0)
result = str.substring(0,str.indexOf(".0")) ;
else
result = str;
}
return result;
}
}
关于怎样给Word2007文档图片加上解说词和如何给word中图片加说明文字的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于c# – Visual Studio 2010中的Word 2007文档、Java 解析 word2007 和 Excel2007、PHPWord解决中文乱码并导出生成Word2007(docx)格式文档、POI 将Excle2003,Excle2007,word2003,word2007转换为html等相关内容,可以在本站寻找。
本文标签: