excel.header.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**创建一个div并固定在底部,将center中的所有a标签放在改div中**/
  2. $("body").append($("<div>").css({"width":"100%","height":"100%px","position":"fixed","top":"0","left":"0"
  3. ,"background-color":"rgba(53, 53, 53, 1)","line-height":"30px","font-size":"13px"}).attr("id","excel-header-nav"));
  4. $("center").css("display", "none");
  5. var centerChildrenA = $("center").children("a");
  6. if (centerChildrenA.length === 0) {
  7. $("#excel-header-nav").hide();
  8. }
  9. $(centerChildrenA).each(function (a, b) {
  10. // 获取a标签对应的target的name值,并设置name对应标签的样式以避免锚点标签标题被覆盖
  11. var href = $(b).attr("href");
  12. var name = href.substr(1);
  13. $("[name=" + name + "]").css({"display":"block","padding-top":"14.01px"});
  14. $(b).css({"padding":"5px","border-right":"1px solid white","color":"#f9f9f9"});
  15. $("#excel-header-nav").append(b);
  16. });
  17. /**给所有的table添加class=table table-striped样式**/
  18. $("table").addClass("table table-striped");
  19. /**
  20. * openoffice,只有一个 colgroup,用col子标签来描述列,liboffice 每一列都是一个colgroup
  21. * var meta = $("meta[name=generator]");
  22. * LibreOffice //OpenOffice
  23. * console.log(meta[0].content);
  24. */
  25. /**计算表头宽度----start**/
  26. function ______getColgroupWidth(colgroups){
  27. var twidth = 0;
  28. $(colgroups).each(function (i, g) {
  29. var w = $(g).attr("width");
  30. var s = $(g).attr("span");
  31. if(null==s || undefined==s){
  32. s=1;
  33. }
  34. twidth +=1*w*s;
  35. });
  36. return twidth;
  37. }
  38. $("table").each(function (a, b) {
  39. var twidth = 0;
  40. var tableChildrenColgroup = $(b).children("colgroup");
  41. if(0==tableChildrenColgroup.length){
  42. }else if(1==tableChildrenColgroup.length){
  43. var cols = tableChildrenColgroup.children("col");
  44. if(0==cols.length){
  45. twidth=______getColgroupWidth(tableChildrenColgroup);
  46. }else{
  47. $(cols).each(function (i, g) {
  48. var w = $(g).attr("width");
  49. twidth +=1*w;
  50. });
  51. }
  52. }else{
  53. twidth = ______getColgroupWidth(tableChildrenColgroup);
  54. }
  55. $(b).css({"width":twidth});
  56. });