attrs = WidgeUtils.parseAttr(widgeType);
29 | String value = attrs.get("value")!=null? attrs.get("value"):"";//属性值
30 | if("".equals(value)){//兼容以前的写法
31 | if(widgeType.indexOf("[") != -1 && widgeType.indexOf("]") != -1){
32 | String values = widgeType.substring(widgeType.indexOf("[")+1,widgeType.indexOf("]"));
33 | valueArray = values.split(",");
34 | }
35 | }else{
36 | valueArray = value.split(",");
37 | }
38 | sb.append("");
39 | String alias = tagId;//别名,不重复即可
40 | for(int i = 0; i < valueArray.length; i++ ){
41 | String v = valueArray[i];
42 | if(i != 0){
43 | tagId = getTagId(table, WIDGE_NAME);
44 | }
45 | sb.append(String.format(
46 | "%s",
47 | tagId, tagId, alias, WIDGE_NAME, fontStyle, v, v));
48 | }
49 | sb.append("
");
50 | return WIDGE_NAME;
51 | }
52 | return "";
53 | }
54 |
55 | @Override
56 | public String parseHtml4View(String widgeType, StringBuilder sb, ExcelTable table, ExcelTableTd td) throws Exception {
57 | double width = td.getWidthNum();
58 | String tagId = getTagId(table, WIDGE_NAME);
59 | String fontStyle = getFontStyle(td);
60 | if (isCur(widgeType)) {
61 | validate(widgeType);
62 | width = width-2-2;//表格长度-padding-边框
63 | String[] valueArray = null;
64 | if(widgeType.indexOf("[") != -1 && widgeType.indexOf("]") != -1){
65 | String values = widgeType.substring(widgeType.indexOf("[")+1,widgeType.indexOf("]"));
66 | valueArray = values.split(",");
67 | }
68 | sb.append("");
69 | String alias = tagId;//别名,不重复即可
70 | for(int i = 0; i < valueArray.length; i++ ){
71 | String v = valueArray[i];
72 | if(i != 0){
73 | tagId = getTagId(table, WIDGE_NAME);
74 | }
75 | sb.append(String.format(
76 | "%s",
77 | tagId, tagId, alias, WIDGE_NAME, fontStyle, v, v));
78 | }
79 | sb.append("
");
80 | return WIDGE_NAME;
81 | }
82 | return "";
83 | }
84 |
85 | @Override
86 | public void validate(String content){
87 |
88 | }
89 |
90 | @Override
91 | public boolean isCur(String widgeType){
92 | if (widgeType.toLowerCase().startsWith(WIDGE_NAME + "[")){//必须是startWith
93 | return true;
94 | }
95 | return false;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/com/codecraft/excel2html/widget/basic/DateWidget.java:
--------------------------------------------------------------------------------
1 | package com.codecraft.excel2html.widget.basic;
2 |
3 | import java.util.Map;
4 |
5 | import com.codecraft.excel2html.cons.ExcelConstant;
6 | import com.codecraft.excel2html.entity.ExcelTable;
7 | import com.codecraft.excel2html.entity.ExcelTableTd;
8 | import com.codecraft.excel2html.utils.WidgeUtils;
9 | import com.codecraft.excel2html.widget.AbsWidget;
10 | /**
11 | * date--时间控件
12 | */
13 | public class DateWidget extends AbsWidget {
14 |
15 | public String WIDGE_NAME = "date".toLowerCase();
16 |
17 | @Override
18 | public String parseHtml4Edit(String widgeType, StringBuilder sb, ExcelTable table, ExcelTableTd td) throws Exception {
19 | double width = td.getWidthNum();
20 | double height = td.getHeightNum();
21 | String tagId = getTagId(table, WIDGE_NAME);
22 | String textAlign = td.getTextAlign();
23 | String fontStyle = getFontStyle(td);
24 | if (isCur(widgeType)) {
25 | validate(widgeType);
26 | int length = 12;
27 | width = width-2-2;//表格长度-padding-边框
28 | Map attrs = WidgeUtils.parseAttr(widgeType);
29 | String format = attrs.get("format")!=null? attrs.get("format"):"";//格式化
30 | String auth = attrs.get("auth")!=null? attrs.get("auth").toLowerCase():"";//编写者(控件id需要转为小写)
31 | if("".equals(format)){
32 | format = "yyyy年MM月dd日";
33 | }
34 | sb.append(String
35 | .format(
36 | "",
39 | width, height, tagId, tagId, WIDGE_NAME, auth, width, height, textAlign, ExcelConstant.WIDGET_BACKGROUND_COLOR, fontStyle, format, length/2));
40 | return WIDGE_NAME;
41 | }
42 | return "";
43 | }
44 |
45 | @Override
46 | public String parseHtml4View(String widgeType, StringBuilder sb, ExcelTable table, ExcelTableTd td) throws Exception {
47 | double width = td.getWidthNum();
48 | double height = td.getHeightNum();
49 | String tagId = getTagId(table, WIDGE_NAME);
50 | String textAlign = td.getTextAlign();
51 | String fontStyle = getFontStyle(td);
52 | if (isCur(widgeType)) {
53 | validate(widgeType);
54 | int length = 12;//时间
55 | Map attrs = WidgeUtils.parseAttr(widgeType);
56 | String auth = attrs.get("auth")!=null? attrs.get("auth"):"";//编写者
57 | width = width-2-2;//表格长度-padding-边框
58 | sb.append(String
59 | .format(
60 | "",
63 | width, height, tagId, tagId, WIDGE_NAME, auth, width, height, textAlign, fontStyle, length/2));
64 | return WIDGE_NAME;
65 | }
66 | return "";
67 | }
68 |
69 | @Override
70 | public void validate(String content){
71 | }
72 |
73 | @Override
74 | public boolean isCur(String widgeType){
75 | if (widgeType.toLowerCase().startsWith(WIDGE_NAME)){
76 | return true;
77 | }
78 | return false;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/main/java/com/codecraft/excel2html/widget/basic/EditorWidget.java:
--------------------------------------------------------------------------------
1 | package com.codecraft.excel2html.widget.basic;
2 |
3 | import com.codecraft.excel2html.entity.ExcelTable;
4 | import com.codecraft.excel2html.entity.ExcelTableTd;
5 | import com.codecraft.excel2html.widget.AbsWidget;
6 |
7 | public class EditorWidget extends AbsWidget {
8 |
9 | public static final String WIDGE_NAME = "editor".toLowerCase();
10 |
11 | @Override
12 | public String parseHtml4Edit(String widgeType, StringBuilder sb,
13 | ExcelTable table, ExcelTableTd td) throws Exception {
14 | return "";
15 | }
16 |
17 | @Override
18 | public String parseHtml4View(String widgeType, StringBuilder sb,
19 | ExcelTable table, ExcelTableTd td) throws Exception {
20 | return "";
21 | }
22 |
23 | @Override
24 | public void validate(String widgeType) throws Exception {
25 |
26 | }
27 |
28 | @Override
29 | public boolean isCur(String widgeType) {
30 | if (widgeType.toLowerCase().startsWith(WIDGE_NAME)){
31 | return true;
32 | }
33 | return false;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/codecraft/excel2html/widget/basic/InputWidget.java:
--------------------------------------------------------------------------------
1 | package com.codecraft.excel2html.widget.basic;
2 |
3 | import com.codecraft.excel2html.entity.ExcelTable;
4 | import com.codecraft.excel2html.entity.ExcelTableTd;
5 | import com.codecraft.excel2html.widget.AbsWidget;
6 |
7 | public class InputWidget extends AbsWidget {
8 |
9 | public static final String WIDGE_NAME = "input".toLowerCase();
10 |
11 | @Override
12 | public String parseHtml4Edit(String widgeType, StringBuilder sb,
13 | ExcelTable table, ExcelTableTd td) throws Exception {
14 |
15 | return "";
16 | }
17 |
18 | @Override
19 | public String parseHtml4View(String widgeType, StringBuilder sb,
20 | ExcelTable table, ExcelTableTd td) throws Exception {
21 |
22 | return "";
23 | }
24 |
25 | @Override
26 | public void validate(String widgeType) throws Exception {
27 |
28 | }
29 |
30 | @Override
31 | public boolean isCur(String widgeType) {
32 | if (widgeType.toLowerCase().startsWith(WIDGE_NAME)){
33 | return true;
34 | }
35 | return false;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/codecraft/excel2html/widget/basic/PicWidget.java:
--------------------------------------------------------------------------------
1 | package com.codecraft.excel2html.widget.basic;
2 |
3 | import java.util.List;
4 |
5 | import com.codecraft.excel2html.entity.ExcelTable;
6 | import com.codecraft.excel2html.entity.ExcelTableTd;
7 | import com.codecraft.excel2html.entity.PictureStyle;
8 | import com.codecraft.excel2html.widget.AbsWidget;
9 |
10 | public class PicWidget extends AbsWidget {
11 |
12 | public static final String WIDGE_NAME = "pic".toLowerCase();
13 |
14 | @Override
15 | public String parseHtml4Edit(String widgetType, StringBuilder sb,
16 | ExcelTable table, ExcelTableTd td) throws Exception {
17 | return parseContent(table);
18 | }
19 |
20 | @Override
21 | public String parseHtml4View(String widgetType, StringBuilder sb,
22 | ExcelTable table, ExcelTableTd td) throws Exception {
23 | return parseContent(table);
24 | }
25 |
26 | @Override
27 | public void validate(String widgetType) throws Exception {
28 |
29 | }
30 |
31 | @Override
32 | public boolean isCur(String widgetType) {
33 | if(widgetType.equalsIgnoreCase(WIDGE_NAME)){
34 | return true;
35 | }
36 | return false;
37 | }
38 |
39 | /**
40 | * 解析图片
41 | * @param table
42 | * @return
43 | */
44 | public String parseContent(ExcelTable table){
45 | List picStyleList = table.getPicStyleList();
46 | if(picStyleList == null || picStyleList.size() == 0){
47 | return "";
48 | }
49 | int index = table.getUsedPicIndex();
50 | PictureStyle picStyle = null;
51 | if(picStyleList.size() > index){
52 | picStyle = picStyleList.get(index);
53 | table.setUsedPicIndex(index++);
54 | }
55 | if(picStyle == null){
56 | return "";
57 | }
58 | double width = picStyle.getWidth();
59 | double height = picStyle.getHeight();
60 | String picUrl = picStyle.getUrl();
61 | String picHtml = String.format(
62 | "
", picUrl, width-4,height);//减去4 表示左右两边2px的留白
63 | return picHtml;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/com/codecraft/excel2html/widget/basic/TextareaWidget.java:
--------------------------------------------------------------------------------
1 | package com.codecraft.excel2html.widget.basic;
2 |
3 | import com.codecraft.excel2html.entity.ExcelTable;
4 | import com.codecraft.excel2html.entity.ExcelTableTd;
5 | import com.codecraft.excel2html.widget.AbsWidget;
6 |
7 | public class TextareaWidget extends AbsWidget {
8 |
9 | public static final String WIDGE_NAME = "textarea".toLowerCase();
10 |
11 | @Override
12 | public String parseHtml4Edit(String widgeType, StringBuilder sb, ExcelTable table, ExcelTableTd td) throws Exception {
13 |
14 | return "";
15 | }
16 |
17 | @Override
18 | public String parseHtml4View(String widgeType, StringBuilder sb, ExcelTable table, ExcelTableTd td) throws Exception {
19 |
20 | return "";
21 | }
22 |
23 | @Override
24 | public void validate(String widgeType) throws Exception {
25 |
26 | }
27 |
28 | @Override
29 | public boolean isCur(String widgeType) {
30 | if (widgeType.toLowerCase().startsWith(WIDGE_NAME)){
31 | return true;
32 | }
33 | return false;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/codecraft/excel2html/widget/calc/CalcNumWidget.java:
--------------------------------------------------------------------------------
1 | package com.codecraft.excel2html.widget.calc;
2 |
3 | import java.util.Map;
4 |
5 | import com.codecraft.excel2html.cons.ExcelConstant;
6 | import com.codecraft.excel2html.entity.ExcelTable;
7 | import com.codecraft.excel2html.entity.ExcelTableTd;
8 | import com.codecraft.excel2html.utils.StringsUtils;
9 | import com.codecraft.excel2html.utils.WidgeUtils;
10 | import com.codecraft.excel2html.widget.AbsWidget;
11 |
12 | /**
13 | * 计算数据来源
14 | */
15 | public class CalcNumWidget extends AbsWidget {
16 |
17 | public static final String WIDGE_NAME = "numtext".toLowerCase();
18 |
19 | @Override
20 | public String parseHtml4Edit(String widgeType, StringBuilder sb, ExcelTable table, ExcelTableTd td) throws Exception {
21 | double width = td.getWidthNum();
22 | String tagId = getTagId(table, WIDGE_NAME);
23 | String textAlign = td.getTextAlign();
24 | String fontStyle = getFontStyle(td);
25 | if (isCur(widgeType)) {
26 | validate(widgeType);
27 | Map attrs = WidgeUtils.parseAttr(widgeType);
28 | int length = 0;
29 | width = width-2-2;//表格长度-padding-边框
30 | String val = attrs.get("val")!=null ? attrs.get("val") : "";//计算值
31 | String text = attrs.get("text")!=null ? attrs.get("text") : "";//显示值
32 |
33 | //overflow:hidden;display:inline-block;white-space:nowrap; 预览时不溢出
34 | if(StringsUtils.isEmpty(val) && StringsUtils.isEmpty(text)){
35 | sb.append(String.format(
36 | "",
37 | tagId, tagId, WIDGE_NAME, val, text, length, width, textAlign, ExcelConstant.WIDGET_BACKGROUND_COLOR, fontStyle));
38 | }else{
39 | sb.append(String.format(
40 | "%s",
41 | tagId, tagId, WIDGE_NAME, val, text, length, width, textAlign, fontStyle, text));
42 | }
43 | return WIDGE_NAME;
44 | }
45 | return "";
46 | }
47 |
48 | @Override
49 | public String parseHtml4View(String widgeType, StringBuilder sb, ExcelTable table, ExcelTableTd td) throws Exception {
50 | double width = td.getWidthNum();
51 | String tagId = getTagId(table, WIDGE_NAME);
52 | String textAlign = td.getTextAlign();
53 | String fontStyle = getFontStyle(td);
54 | if (isCur(widgeType)) {
55 | validate(widgeType);
56 | Map attrs = WidgeUtils.parseAttr(widgeType);
57 | int length = 0;
58 | width = width-2-2;//表格长度-padding-边框
59 | String val = attrs.get("val")!=null ? attrs.get("val") : "" ;//计算值
60 | String text = attrs.get("text")!=null ? attrs.get("text") : "";//显示值
61 |
62 | //overflow:hidden;display:inline-block;white-space:nowrap; 预览时不溢出
63 | sb.append(String.format(
64 | "%s",
65 | tagId, tagId, WIDGE_NAME, val, text, length, width, textAlign, fontStyle, text));
66 | return WIDGE_NAME;
67 | }
68 | return "";
69 | }
70 |
71 | @Override
72 | public void validate(String content)throws Exception {
73 |
74 | }
75 |
76 | @Override
77 | public boolean isCur(String widgeType){
78 | if (widgeType.toLowerCase().startsWith(WIDGE_NAME)){
79 | return true;
80 | }
81 | return false;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/com/codecraft/excel2html/widget/calc/CalcRltWidget.java:
--------------------------------------------------------------------------------
1 | package com.codecraft.excel2html.widget.calc;
2 |
3 | import java.util.Map;
4 |
5 | import com.codecraft.excel2html.cons.ExcelConstant;
6 | import com.codecraft.excel2html.entity.ExcelTable;
7 | import com.codecraft.excel2html.entity.ExcelTableTd;
8 | import com.codecraft.excel2html.utils.WidgeUtils;
9 | import com.codecraft.excel2html.widget.AbsWidget;
10 |
11 | /**
12 | * 最终计算结果显示(也可以当做计算来源)
13 | * @description
14 | * exps 表达式 A*B
15 | * format 格式化
16 | * prec 精度(必须为正整数)
17 | * rigor 严格计算.表达式A*B 其中有一个变量值为''时,计算结果为Null (不设置此属性时,变量值为''当做0来计算)
18 | * @author zoro
19 | */
20 | public class CalcRltWidget extends AbsWidget {
21 |
22 | public static final String WIDGE_NAME = "calc".toLowerCase();
23 |
24 | @Override
25 | public String parseHtml4Edit(String widgeType, StringBuilder sb, ExcelTable table ,ExcelTableTd td) throws Exception {
26 | double width = td.getWidthNum();
27 | double height = td.getHeightNum();
28 | String tagId = getTagId(table, WIDGE_NAME);
29 | String textAlign = td.getTextAlign();
30 | String fontStyle = getFontStyle(td);
31 |
32 | if (isCur(widgeType)) {
33 | validate(widgeType);
34 | Map attrs = WidgeUtils.parseAttr(widgeType);
35 | int length = 0;
36 |
37 | width = width-2-2;//表格长度-padding-边框
38 |
39 | String exps = attrs.get("exps").toLowerCase();//公式
40 | String format = attrs.get("format")!=null? attrs.get("format").toLowerCase():"";//格式化
41 | String prec = attrs.get("prec")!=null? attrs.get("prec"):"";//精度precision
42 | String rigor = attrs.get("rigor")!=null? attrs.get("rigor"):"";//严格计算
43 | //overflow:hidden;display:inline-block;white-space:nowrap;
44 | sb.append(String
45 | .format(
46 | "",
49 | width, height, tagId, tagId, WIDGE_NAME, exps, format, prec, rigor, width, height, textAlign, ExcelConstant.WIDGET_BACKGROUND_COLOR, fontStyle, length/2));
50 | return WIDGE_NAME;
51 | }
52 | return "";
53 | }
54 |
55 | @Override
56 | public String parseHtml4View(String widgeType, StringBuilder sb, ExcelTable table ,ExcelTableTd td) throws Exception {
57 | double width = td.getWidthNum();
58 | double height = td.getHeightNum();
59 | String tagId = getTagId(table, WIDGE_NAME);
60 | String textAlign = td.getTextAlign();
61 | String fontStyle = getFontStyle(td);
62 |
63 | if (isCur(widgeType)) {
64 | validate(widgeType);
65 | Map attrs = WidgeUtils.parseAttr(widgeType);
66 | int length = 0;
67 | width = width-2-2;//表格长度-padding-边框
68 |
69 | String exps = attrs.get("exps");//公式
70 | String format = attrs.get("format");//格式化
71 | String prec = attrs.get("prec")!=null? attrs.get("prec"):"";//精度
72 | String rigor = attrs.get("rigor")!=null? attrs.get("rigor"):"";//严格计算
73 | sb.append(String
74 | .format(
75 | "",
78 | width, height, tagId, tagId, WIDGE_NAME, exps, format, prec, rigor, width, height, textAlign, fontStyle, length/2));
79 | return WIDGE_NAME;
80 | }
81 | return "";
82 | }
83 |
84 | @Override
85 | public void validate(String widgeType) throws Exception{
86 |
87 | }
88 |
89 | @Override
90 | public boolean isCur(String widgeType){
91 | if (widgeType.toLowerCase().startsWith(WIDGE_NAME)){
92 | return true;
93 | }
94 | return false;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/target/classes/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Built-By: Administrator
3 | Build-Jdk: 1.7.0_45
4 | Created-By: Maven Integration for Eclipse
5 |
6 |
--------------------------------------------------------------------------------
/target/classes/META-INF/maven/com.codecraft/Excel2Html/pom.properties:
--------------------------------------------------------------------------------
1 | #Generated by Maven Integration for Eclipse
2 | #Fri Dec 09 16:03:28 CST 2016
3 | version=0.0.1-SNAPSHOT
4 | groupId=com.codecraft
5 | m2e.projectName=Excel2Html
6 | m2e.projectLocation=C\:\\Users\\Administrator\\Workspaces\\MyEclipse Professional 2014\\Excel2Html
7 | artifactId=Excel2Html
8 |
--------------------------------------------------------------------------------
/target/classes/META-INF/maven/com.codecraft/Excel2Html/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.codecraft
6 | Excel2Html
7 | 0.0.1-SNAPSHOT
8 | jar
9 |
10 | Excel2Html
11 | http://maven.apache.org
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 |
19 | junit
20 | junit
21 | 3.8.1
22 | test
23 |
24 |
25 |
26 | org.apache.poi
27 | poi
28 | 3.12
29 |
30 |
31 |
32 | org.apache.poi
33 | poi-examples
34 | 3.12
35 |
36 |
37 |
38 | org.apache.poi
39 | poi-ooxml
40 | 3.12
41 |
42 |
43 |
44 | org.apache.poi
45 | poi-ooxml-schemas
46 | 3.12
47 |
48 |
49 |
50 | org.apache.poi
51 | poi-scratchpad
52 | 3.12
53 |
54 |
55 |
56 | org.apache.xmlbeans
57 | xmlbeans
58 | 2.3.0
59 |
60 |
61 |
62 | org.json
63 | json
64 | 20080701
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------