Ver código fonte

sytle.awk format_xml.sh

robert 4 anos atrás
pai
commit
bd2d81fe07
2 arquivos alterados com 68 adições e 2 exclusões
  1. 12 2
      format_xml.sh
  2. 56 0
      style.awk

+ 12 - 2
format_xml.sh

@@ -1,6 +1,7 @@
 export LANG=zh_CN.UTF-8@cjknarrow
-#git diff  --name-only  HEAD 策划脚本| grep '\.xml$'|xargs sed -b -i \
-/usr/bin/find  策划脚本 -name '*.xml' | xargs sed -b -i \
+git config core.quotepath 0
+# /usr/bin/find  策划脚本 -name '*.xml' | xargs sed -b -i \
+git diff  --name-only  HEAD 策划脚本| grep '\.xml$'|xargs sed -b -i \
     -e '/^ *<Active\(Sheet\|Row\|Col\)>/d' \
     -e '/^ *<\(TopRowBottom\|LeftColumnRight\)Pane>/d' \
     -e '/^ *<Selected\/>/d' \
@@ -10,8 +11,17 @@ export LANG=zh_CN.UTF-8@cjknarrow
     -e '/^ *<LastSaved/d' \
     -e '/^ *<LeftColumnVisible/d' \
     -e '/<Panes>/,/<\/Panes>/d' \
+    -e '/<Table */,/>/s/ ss:StyleID="\w\+"//' \
+    -e '/<Column .*\/>/d' \
+    -e '/<Column /,/\/>/d' \
     -e '/<ConditionalFormatting xmlns/,/<\/ConditionalFormatting>/d' \
     -e '/<WorksheetOptions xmlns/,/<\/WorksheetOptions>/d' \
     -e '/^ *<Split/d' 
 
+# /usr/bin/find  策划脚本 -name '*.xml' | while read n;
+git diff  --name-only  HEAD 策划脚本| grep '\.xml$'| while read n ; 
+do 
+    awk -f style.awk "$n" > awk.tmp
+    mv awk.tmp "$n"
+done
 

+ 56 - 0
style.awk

@@ -0,0 +1,56 @@
+BEGIN{
+    styles=0
+    in_style=0
+    rows=-1
+}
+{
+
+    if(match($0,"^ *<Table")){
+        rows=0
+        print
+        next
+    }
+    if(match($0,"^ *</Table")){
+        rows=-1
+        print
+        next
+    }
+    if(match($0,"^ *<Row[ >]")){
+        if(rows<4)rows++
+    }
+    if(rows>-1){
+        if(rows<4)
+            gsub(" ss:StyleID=\"\\w+\""," ss:StyleID=\"s1\"",$0)
+        else
+            gsub(" ss:StyleID=\"\\w+\"","",$0)
+    }
+    # if(match($0,"^ *<Style ")){
+        # if(styles<3) styles++
+    # }
+
+    if(match($0,"^ *<Style ")){
+        in_style=1
+        if(styles==0){
+            styles++
+            print
+            next
+        }
+        else if(styles==1) {
+            gsub("ss:ID=\"\\w+\"","ss:ID=\"s1\"",$0)
+            styles++
+            print $0
+            next
+        } else {
+            if(styles<3) styles++
+            in_style=1
+        }
+    }
+
+    if(match($0,"^ *</Style>")){
+        in_style=0
+        if(styles>2 )next
+    }
+    if(in_style && styles>2 )next
+
+    print $0
+}