java操作word中的excel(对应的是图表,如柱状图)
我.net中也遇到了相同的问题:你可以先看一下下面代码,应该大部分你能用到,只是chart属性可能有点问题,之前尝试成功过,但是由于我不小心删除了一些系统文件里的内容,就有些运行不起来了
我是先循环的word中的shape
foreach (Microsoft.Office.Interop.Word.Shape shape in docFile.Shapes)
{
if(shape.Name=="Chart_图表")
{
shape.Chart.ChartData.Activate();
Microsoft.Office.Interop.Excel.Workbook wb = (Microsoft.Office.Interop.Excel.Workbook)shape.Chart.ChartData.Workbook;
Microsoft.Office.Interop.Excel.Worksheet wSh = (Microsoft.Office.Interop.Excel.Worksheet)wb.Worksheets[1];
//然后添加新数据
for (int r = 0; r < tempdt.Rows.Count; r++)
{
for (int k = 0; k < tempdt.Columns.Count; k++)
{
Microsoft.Office.Interop.Excel.Range Rng1 = wSh.Cells[r + 2, k + 1] as Microsoft.Office.Interop.Excel.Range;
Rng1.Value = tempdt.Rows[r][k];
}
}
wb.Application.ScreenUpdating = true;
wb.Close(Type.Missing, Type.Missing, Type.Missing);
chart.Refresh();
shape.Chart.Refresh();
}
}
Java如何操作Word?Java如何操作Word,Excel,
Java Excel API 文档 http://www。
andykhan。com/jexcelapi/ 1、一个jacob操作Word的例子,其他操作excel,pdf的sample里都有 import java。
io。File; import com。
jacob。com。
*; import com。jacob。
activeX。*; public class WordTest { public static void main(String[] args) { WordBean word=new WordBean(); word。
openWord(true); word。createNewDocument(); word。
insertText("Hello word。"); } } import com。
jacob。activeX。
*; import com。 jacob。
com。*; public class WordBean extends java。
awt。Panel { private ActiveXComponent MsWordApp = null; private Dispatch document = null; public WordBean() { super(); } public void openWord(boolean makeVisible) { //Open Word if we've not done it already if (MsWordApp == null) { MsWordApp = new ActiveXComponent("Word。
Application"); } //Set the visible property as required。 Dispatch。
put(MsWordApp, "Visible", new Variant(makeVisible)); } public void createNewDocument() { //Find the Documents collection object maintained by Word Dispatch documents = Dispatch。 get(MsWordApp,"Documents")。
toDispatch(); //Call the Add method of the Documents collection to create //a new document to edit document = Dispatch。 call(documents,"Add")。
toDispatch(); } public void insertText(String textToInsert) { // Get the current selection within Word at the moment。 If // a new document has just been created then this will be at // the top of the new doc Dispatch selection = Dispatch。
get(MsWordApp,"Selection")。toDispatch(); //Put the specified text at the insertion point Dispatch。
put(selection,"Text",textToInsert); } public void saveFileAs(String filename) { Dispatch。 call(document,"SaveAs",filename); } public void printFile() { //Just print the current document to the default printer Dispatch。
call(document,"PrintOut"); } public void closeDocument() { // Close the document without saving changes // 0 = wdDoNotSaveChanges // -1 = wdSaveChanges // -2 = wdPromptToSaveChanges Dispatch。 call(document, "Close", new Variant(0)); document = null; } public void closeWord() { Dispatch。
call(MsWordApp,"Quit"); MsWordApp = null; document = null; } }。
怎么用java poi生成word表格
rt java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class XwpfTUtil {
/*String filePath = "/sta.docx";
InputStream is;
XWPFDocument doc;
Mapparams = new HashMap();
{
params.put("${name}", "xxx");
params.put("${sex}", "男");
params.put("${political}", "共青团员");
params.put("${place}", "sssss");
params.put("${classes}", "3102");
params.put("${id}", "213123123");
params.put("${qq}", "213123");
params.put("${tel}", "312313213");
params.put("${oldJob}", "sadasd");
params.put("${swap}", "是");
params.put("${first}", "asdasd");
params.put("${second}", "综合事务部");
params.put("${award}", "asda");
params.put("${achievement}", "完成科协网站的开发");
params.put("${advice}", "没有建议");
java导出word表格
首先我用的技术是 poi 这是代码,一个工具类得调用 public class WordUtil { /** * 基于模板文件导出 word 文档,此方法主要是用来处理文档中需要替换的文本内容,对图片和表格无效 * * @param templatePath * 模板文件的路径,要求路径中要包含全名,并且模板文件只能是 07 及以上格式,即 docx 的文件 * @param destFilePath * 导出文件的存放路径,包含文件名,例如,E:/test/小区公告.docx * @param data * 用来替换文档中预定义的字符串,要求预定义的字符串与 data 中的 key 值要相同 */ public static void exportWordByTemplate(String templatePath, String destFilePath, Map E:/test/test.doc 新生成的地址。 1.JAVA程序能直接运行吗? -----不能,必须要编译成CLASS文件才能运行 2.如果做出个JAVA程序 他要怎么运行? ----- JAVA程序-->;编译-->;解析执行 第一个"-->;",用JAVAC命令。第二个"-->;",用JAVA命令。 3.难道只能在DOS下运行吗? -----不是。你可以用开发工具执行,如Jbuider,它可以将“-->;编译-->;解析执行”集成在一个按钮中。另外你可以将编译后的CLASS文件打包成JAR运行。 转载请注明出处51数据库 » javaword图表 JAVA文件为什么是文本图标