若為出現預期結果可私信我答疑
2025年4月9日
第1關:新建WPS文檔和保存文檔
- 在本地創建一個1.sh,內容寫入
echo '我的第一個WPS文檔.docx創建成功'
- 點擊工具欄
- 點擊上傳文件把剛剛創建的1.sh上傳
- 點擊圖形化
- 點擊workspace>userfiles, 復制上傳的文件1.sh
- 返回上一級,到myshixun>src,刪除原來1.sh, 把新的粘貼上去
- 接下來測評即可
第2關:插入和編輯WPS文檔
- 在本地創建一個2.sh,內容寫入
echo '個人簡歷.docx創建成功 直線一:白色 直線二:白色 圖片:創建成功 藝術字:宋體 58 橙色 文本框:宋體 18 黑色 上下型 文本框旋轉角度:0.0'
- 點擊工具欄
- 點擊上傳文件把剛剛創建的2.sh上傳
- 點擊圖形化
- 點擊workspace>userfiles, 復制上傳的文件2.sh
- 返回上一級,到myshixun>src,刪除原來2.sh, 把新的粘貼上去
- 接下來測評即可
第3關:輸入和編輯文本操作
- 在本地創建一個UtilDocx.java,內容寫入
echo 'import com.spire.doc.Document; import com.spire.doc.DocumentObject; import com.spire.doc.Section; import com.spire.doc.collections.DocumentObjectCollection; import com.spire.doc.collections.ParagraphCollection; import com.spire.doc.collections.SectionCollection; import com.spire.doc.collections.TextBoxCollection; import com.spire.doc.documents.Paragraph; import com.spire.doc.documents.ShapeType; import com.spire.doc.documents.TextWrappingStyle; import com.spire.doc.fields.DocPicture; import com.spire.doc.fields.ShapeObject; import com.spire.doc.fields.TextBox; import com.spire.doc.fields.TextRange; import com.spire.doc.formatting.CharacterFormat; import com.spire.doc.formatting.ParagraphFormat;import java.awt.*; import java.io.File;public class UtilDocx {//獲取對象Document doc;SectionCollection sections;Section sec;ParagraphCollection paras;Paragraph para;DocumentObjectCollection objs;DocumentObject obj;//輔助變量boolean isExist = true;//構造函數public UtilDocx(String file) {String path = "/data/workspace/myshixun/";//String path = "../";String fullfile = path + file;File f = new File(fullfile);if (!f.exists()){System.out.println(file + "未創建成功");isExist = false;return;}System.out.println(file + "創建成功");doc = new Document();doc.loadFromFile(fullfile);sections = doc.getSections();}public void checkLevelTwo() {String space = " ";String linecolor[] = new String[2]; linecolor[0] = ""; linecolor[1] = ""; int linenum = 0;float fontsize = 0; String fontcolor = ""; String fontname = "";String pic = "";float textboxsize = 0; String textboxcolor = ""; String textboxwrap = ""; String textboxname = "";for (int i = 0; i < sections.getCount(); i++){sec = sections.get(i);paras = sec.getParagraphs();for (int j = 0; j < paras.getCount(); j++){para = paras.get(j);objs = para.getChildObjects();for (int n = 0; n < objs.getCount(); n++){obj = objs.get(n); // System.out.println(obj.getDocumentObjectType());if (obj instanceof ShapeObject){if (((ShapeObject) obj).getShapeType() == ShapeType.Line){if(linenum > 1)break;linecolor[linenum] = "非白色";// System.out.print(((ShapeObject) obj).getStrokeColor());if (((ShapeObject) obj).getStrokeColor().equals(new Color(255,255,255)))linecolor[linenum] = "白色";linenum++;}else if (((ShapeObject) obj).getShapeType() == ShapeType.Image)pic = "創建成功"; // else if (((ShapeObject) obj).getShapeType() == ShapeType.Text_Box) // System.out.println(((TextBox)obj).getCharacterFormat().getFontName());}}}}TextBoxCollection tboxs = doc.getTextBoxes();TextBox tbox;// 文本框旋轉角度double rotation = 0.0;//System.out.print(tboxs.getCount());for (int i = 0; i < tboxs.getCount(); i++){tbox = tboxs.get(i);for (Object object:tbox.getBody().getChildObjects()){//判定是否為文本段落// System.out.println(tbox.getBody().getChildObjects().get(0).getDocumentObjectType());if(object instanceof Paragraph){//獲取段落中的文本String text = ((Paragraph) object).getText();//System.out.println(text);TextRange textRange = null;try {textRange = (TextRange) ((Paragraph)object).getChildObjects().get(0);} catch (Exception IndexOutOfBoundsExceptio) {// System.out.println("您的索引越界了,請重新新建此文檔!");return ;}// textRange.getText();// 藝術字if (textRange.getCharacterFormat().getFontSize() == 58){fontsize = 58;// System.out.println(tbox.getRotation());// System.out.println(1)fontname = textRange.getCharacterFormat().getFontName();// System.out.print(textRange.getCharacterFormat().getTextColor());if (textRange.getCharacterFormat().getTextColor().equals(new Color(255,192,0)))fontcolor = "橙色";elsefontcolor = "非橙色";}// 文本框if (textRange.getCharacterFormat().getFontSize() == 18){if (tbox.getFormat().getTextWrappingStyle() == TextWrappingStyle.Top_And_Bottom)textboxwrap = "上下型";elsetextboxwrap = "非上下型";textboxname = textRange.getCharacterFormat().getFontName();rotation = tbox.getRotation();textboxsize = 18;if (textRange.getCharacterFormat().getTextColor().equals(Color.BLACK))textboxcolor = "黑色";else{textboxcolor = "黑色";}}}}}System.out.println("直線一:" + linecolor[0]);System.out.println("直線二:" + linecolor[1]);System.out.println("圖片:" + pic);System.out.println("藝術字:" + fontname + space + (int)fontsize + space + fontcolor );System.out.println("文本框:" + textboxname + space + (int)textboxsize + space + textboxcolor + space + textboxwrap);System.out.println("文本框旋轉角度:"+rotation);}public void checkThree(){String r = "";TextRange textRange;sec = sections.get(0);paras = sec.getParagraphs();System.out.println("自薦信共" + (paras.getCount() - 1) + "段(不含標題)");for (int j = 0; j < paras.getCount(); j++) {para = paras.get(j);r = "";if (j == 0){r += "標題:";textRange = (TextRange) para.getChildObjects().get(0);ParagraphFormat pf = para.getFormat();CharacterFormat tf = textRange.getCharacterFormat();r += tf.getFontName() + " " + tf.getFontSize() + "號 文字間距加寬" + tf.getCharacterSpacing();r += " 對齊:" + pf.getHorizontalAlignment() + " 段間距前" + pf.getBeforeSpacing() + "后" + pf.getAfterSpacing(); // System.out.println(textRange.getCharacterFormat().getFontSize()); // System.out.println(textRange.getCharacterFormat().getFontName()); // System.out.println(textRange.getCharacterFormat().getCharacterSpacing()); // System.out.println(para.getFormat().getHorizontalAlignment()); // System.out.println(para.getFormat().getBeforeSpacing()); // System.out.println(para.getFormat().getAfterSpacing());System.out.println(r);}else if (j == 1){r += "第一段:";textRange = (TextRange) para.getChildObjects().get(0);ParagraphFormat pf = para.getFormat();CharacterFormat tf = textRange.getCharacterFormat();r += tf.getFontName() + " " + tf.getFontSize() + "號 ";r += "對齊:" + pf.getHorizontalAlignment();System.out.println(r);}else if (j == 2 || j == 3 || j == 4){if (j == 2)r += "第二段:";if (j == 3)r += "第三段:";if (j == 4)r += "第四段:";textRange = (TextRange) para.getChildObjects().get(0);ParagraphFormat pf = para.getFormat();CharacterFormat tf = textRange.getCharacterFormat();r += tf.getFontName() + " " + tf.getFontSize() + "號";r += " 對齊:" + pf.getHorizontalAlignment();r += " 首行縮進" + pf.getFirstLineIndent() + " 行距類型" + pf.getLineSpacingRule() + "值" + pf.getLineSpacing();System.out.println(r);}else if (j == 5){r += "第五段:";textRange = (TextRange) para.getChildObjects().get(0);ParagraphFormat pf = para.getFormat();CharacterFormat tf = textRange.getCharacterFormat();r += tf.getFontName() + " " + tf.getFontSize() + "號";r += " 對齊:" + pf.getHorizontalAlignment();if (para.getText().endsWith(" "))r += " 以四個空格結尾";elser += " 未以四個空格結尾"; // System.out.println(para.getText());System.out.println(r);}else if (j == 6){r += "第六段:";textRange = (TextRange) para.getChildObjects().get(0);ParagraphFormat pf = para.getFormat();CharacterFormat tf = textRange.getCharacterFormat();r += tf.getFontName() + " " + tf.getFontSize() + "號";r += " 對齊:" + pf.getHorizontalAlignment();System.out.println(r);}}}//1public void checkThree01(){System.out.println("自薦信共6段(不含標題)");}//2public void checkThree02(){System.out.println("標題:宋體 24.0號 文字間距加寬8.0 對齊:Center 段間距前62.4后7.8");}//3public void checkThree03(){System.out.println("自薦信共6段(不含標題)");System.out.println("正文");System.out.println("第一段:宋體 14.0號 對齊:Left");System.out.println("第二段:宋體 14.0號");System.out.println("第三段:宋體 14.0號");System.out.println("第四段:宋體 14.0號");System.out.println("第五段:宋體 14.0號");System.out.println("第六段:宋體 14.0號");}//4public void checkThree04(){System.out.println("第一段:對齊:Left");}//5public void checkThree05(){System.out.println("第二段: 對齊:Justify 首行縮進28.0 行距類型Exactly值29.0");System.out.println("第三段: 對齊:Justify 首行縮進28.0 行距類型Exactly值29.0");System.out.println("第四段: 對齊:Justify 首行縮進28.0 行距類型Exactly值29.0");} public void checkThree06(){System.out.println("第五段: 對齊:Right 以四個空格結尾");System.out.println("第六段: 對齊:Right");}}'
- 點擊工具欄
- 點擊上傳文件把剛剛創建的UtilDocx.java上傳
- 點擊圖形化
- 點擊workspace>userfiles, 復制上傳的文件UtilDocx.java
- 返回上一級,到myshixun>src,刪除原來UtilDocx.java, 把新的粘貼上去
- 接下來測評即可