Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用SAX知道page word文档的参数?_Java_Sax - Fatal编程技术网

Java 如何使用SAX知道page word文档的参数?

Java 如何使用SAX知道page word文档的参数?,java,sax,Java,Sax,如何使用SAX知道page Word文档(PageSetup)的参数? 所需的字段纸张大小、上页边距、左页边距值等。好的,我找到了答案。使用w:pgSz,w:pgMar: public Integer PunctToMM(String Punct) { long size = Integer.parseInt(Punct); size = Math.round(0.3528 * size / 20); int value = (int) size; re

如何使用SAX知道page Word文档(PageSetup)的参数?
所需的字段纸张大小、上页边距、左页边距值等。

好的,我找到了答案。使用
w:pgSz
w:pgMar

public Integer PunctToMM(String Punct) {

     long size = Integer.parseInt(Punct);
     size = Math.round(0.3528 * size / 20);
     int value = (int) size;
     return value;

 }

    public void startElement(String uri, String localName,
         String qName, Attributes attributes) throws SAXException {

         switch (qName) {
         case "w:pgSz":

             attributesVAL = attributes.getValue("w:w");
             System.out.println("width page " + PunctToMM(attributesVAL) + " mm.");

             attributesVAL = attributes.getValue("w:h");
             System.out.println("height page " + PunctToMM(attributesVAL) + " mm.");

             attributesVAL = attributes.getValue("w:code");
             if (attributesVAL == "9") {
                 attributesVAL = "A4";
             } else attributesVAL = "NO A4";
             System.out.println("format page " + attributesVAL);

             break;

         case "w:pgMar":

             attributesVAL = attributes.getValue("w:top");
             System.out.println("top margin " + PunctToMM(attributesVAL) + " mm.");

             attributesVAL = attributes.getValue("w:right");
             System.out.println("right margin " + PunctToMM(attributesVAL) + " mm.");

             attributesVAL = attributes.getValue("w:bottom");
             System.out.println("bottom margin " + PunctToMM(attributesVAL) + " mm.");

             attributesVAL = attributes.getValue("w:left");
             System.out.println("left margin " + PunctToMM(attributesVAL) + " mm.");

             break;

         default:
             break;
     }

 }