style.awk 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. BEGIN{
  2. styles=0
  3. in_style=0
  4. rows=-1
  5. }
  6. {
  7. if(match($0,"^ *<Table")){
  8. rows=0
  9. print
  10. next
  11. }
  12. if(match($0,"^ *</Table")){
  13. rows=-1
  14. print
  15. next
  16. }
  17. if(match($0,"^ *<Row[ >]")){
  18. if(rows<4)rows++
  19. }
  20. if(rows>-1){
  21. if(rows<4)
  22. gsub(" ss:StyleID=\"\\w+\""," ss:StyleID=\"s1\"",$0)
  23. else
  24. gsub(" ss:StyleID=\"\\w+\"","",$0)
  25. }
  26. # if(match($0,"^ *<Style ")){
  27. # if(styles<3) styles++
  28. # }
  29. if(match($0,"^ *<Style ")){
  30. in_style=1
  31. if(styles==0){
  32. styles++
  33. print
  34. next
  35. }
  36. else if(styles==1) {
  37. gsub("ss:ID=\"\\w+\"","ss:ID=\"s1\"",$0)
  38. styles++
  39. print $0
  40. next
  41. } else {
  42. if(styles<3) styles++
  43. in_style=1
  44. }
  45. }
  46. if(match($0,"^ *</Style>")){
  47. in_style=0
  48. if(styles>2 )next
  49. }
  50. if(in_style && styles>2 )next
  51. print $0
  52. }