这是我第一次使用Apache POI,我已经在本网站上提出了我要问的问题,但没有给出明确的答案,所以我别无选择,只能接受你的帮助.
我正在尝试编写一个java程序,它从一个文件夹中获取图像并将该图像插入到word文档中.我在这个程序中使用Apache POI.我在这里发布我的代码.
import java.io.*;
import java.util.*;
import org.apache.poi.util.IOUtils;
import org.apache.poi.xwpf.usermodel.*;
public class ImagesDoc
{
public static void main(String[] args) throws IOException
{
XWPFDocument docx = new XWPFDocument();
XWPFParagraph par = docx.createParagraph();
XWPFRun run = par.createRun();
run.setText("Hello, World. This is my first java generated docx-file. Have fun.");
run.setFontSize(13);
InputStream pic = new FileInputStream("C:\\Users\\amitabh\\Pictures\\pics\\pool.jpg");
byte [] picbytes = IOUtils.toByteArray(pic);
docx.addPicture(picbytes, Document.PICTURE_TYPE_JPEG);
FileOutputStream out = new FileOutputStream("C:\\Users\\amitabh\\Pictures\\pics\\simple1.docx");
docx.write(out);
out.close();
pic.close();
}
}
Run Code Online (Sandbox Code Playgroud)
我能够创建word文档文件,我也可以插入文本,但是docx.addPicture(picbytes, Document.PICTURE_TYPE_JPEG);行给出了错误"add cast to docx".我为这个程序添加了所有可能的罐子.对于这个错误,我在网上搜索,发现很多人都有类似的问题.XWPFDocument引用的"addPicture"无法正常工作.请帮我解决这个问题.
我的for循环为我的字符串压缩有点偏.过去5天我一直在做这项任务,我无法弄清楚我的生活有什么不对.有人可以帮我吗?
例如,我通过了字符串"TTTTrrrEe",而不是得到T4r3Ee,我得到了T4r3EeTT.我不知道为什么它跳回这样的字符串的开头,但我正在逐渐closer.We只能用charAt,equals,length,并substring从字符串类.
有人可以通过帮助纠正我的逻辑来帮助指导我朝着正确的方向前进吗?我仍然想尝试自己编写代码,看看它是如何分配的.
public static String compress(String s){
int count = 0;
String temp = s.substring(0,1);
for(int i = 0; i < s.length(); i++){
if(i !=s.length()-1){
if(temp.equals(s.substring(i,i+1))){
count++;
}else{
if(count < 1){
System.out.print(s.substring(i,i+2));
System.out.print(temp.substring(0,1) );
}else{
System.out.print("" + temp.substring(0,1) + count);
i--;
temp = s.substring(count,count+1);
System.out.println(" temp is now " + temp);
count = 0;
//i--;
}
}
}
}
System.out.println(temp);
return temp;
}
Run Code Online (Sandbox Code Playgroud) 我需要在线创建UML类图并从中生成Java代码.
像cacoo这样的绘图工具不允许生成代码,因为它们不是真正的UML建模者.
有没有人知道生成Java代码的UML在线工具?
谢谢你的帮助~~