string CreateCode(Dictionary <string, ExcelDatas> datas, ExcelDatas model, string strnamespace, Action <string> show, StringBuilder builderDB, string strspce = " ") { StringBuilder csharpBuilder = new StringBuilder(); string sheetName = model.SheetName; builderDB.AppendLine(" public System.Data.Entity.DbSet<Q" + sheetName.Replace("q_", "") + "> Q" + sheetName.Replace("q_", "") + "s { get; set; } "); csharpBuilder.AppendLine("namespace " + strnamespace) .AppendLine("{") .AppendLine() .AppendLine() .AppendLine(strspce + "using System;") .AppendLine(strspce + "using System.Xml.Serialization;") .AppendLine(strspce + "using System.Collections;") .AppendLine(strspce + "using System.Collections.Generic;") .AppendLine(strspce + "using System.Linq;") .AppendLine(strspce + "using System.Text;") .AppendLine(strspce + "using System.Xml;") .AppendLine() .AppendLine(strspce + "/// <summary>") .AppendLine(strspce + "/// ") .AppendLine(strspce + "/// <para>Excel Data To CSharp CodeFirst Class</para>") .AppendLine(strspce + "/// <para>@Create Code:失足程序员</para>") .AppendLine(strspce + "/// <para>@Create Time:" + (DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:sss")) + "</para>") .AppendLine(strspce + "/// <para>@Phone:13882122019</para>") .AppendLine(strspce + "/// <para>@email:[email protected]</para>") .AppendLine(strspce + "/// </summary>") .AppendLine(strspce + "[System.ComponentModel.DataAnnotations.Schema.Table(\"" + sheetName + "" + "\")]") .AppendLine(strspce + "public class Q" + sheetName.Replace("q_", "") + "") .AppendLine(strspce + "{") .AppendLine(); foreach (var row in model.Rows) { var cells = row.Value.Cells; foreach (var cell in cells) { csharpBuilder .AppendLine(strspce + " /// <summary> ") .AppendLine(strspce + " /// " + cell.CellNotes) .AppendLine(strspce + " /// <para>" + (String.IsNullOrWhiteSpace(cell.CellFileName) ? "" : "关联文件:" + cell.CellFileName) + "</para>") .AppendLine(strspce + " /// </summary> "); if (cell.IsPKey) { csharpBuilder.AppendLine(strspce + " [System.ComponentModel.DataAnnotations.Key, System.ComponentModel.DataAnnotations.Schema.DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)]"); } csharpBuilder.AppendLine(strspce + " [System.ComponentModel.DataAnnotations.Schema.Column(\"" + cell.CellName + "\")]") .AppendLine(strspce + " public " + cell.CellValueType + " Q" + cell.CellName.Replace("q_", "") + " { get; set; }") .AppendLine(); } break; } csharpBuilder.AppendLine(strspce + "}"); // Class End csharpBuilder.AppendLine("}"); // namespace End return(csharpBuilder.ToString()); }
string CreateCode(Dictionary <string, ExcelDatas> datas, ExcelDatas model, string strnamespace, Action <string> show) { StringBuilder csharpBuilder = new StringBuilder(); string sheetName = model.SheetName; csharpBuilder.Append("package ").Append(strnamespace).AppendLine(";") .AppendLine() .AppendLine() .AppendLine("import java.io.Serializable;") .AppendLine("import javax.persistence.Column;") .AppendLine("import javax.persistence.Entity;") .AppendLine("import javax.persistence.GeneratedValue;") .AppendLine("import javax.persistence.GenerationType;") .AppendLine("import javax.persistence.Id;") .AppendLine("import javax.persistence.Table;") .AppendLine() .AppendLine("/**") .AppendLine("* ") .AppendLine("* <br>") .AppendLine("* Excel Data To Java Jpa C3P0 Class<br>") .AppendLine("* Create Code:失足程序员<br>") .AppendLine("* blog http://www.cnblogs.com/ty408/<br>") .AppendLine("* Create Time:" + (DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:sss")) + "<br>") .AppendLine("* Phone:13882122019<br>") .AppendLine("* email:[email protected]<br>") .AppendLine("**/") .AppendLine("@Entity") .AppendLine("@Table(name = \"" + sheetName + "" + "\")") .AppendLine("public class Q" + sheetName.Replace("q_", "") + " implements Serializable {") .AppendLine(); foreach (var row in model.Rows) { var cells = row.Value.Cells; foreach (var cell in cells) { if ("ALL".Equals(cell.Cellgs) || "AS".Equals(cell.Cellgs)) { csharpBuilder .AppendLine(" /**") .AppendLine(" * " + cell.CellNotes) .AppendLine(" * " + (String.IsNullOrWhiteSpace(cell.CellFileName) ? "" : "关联文件:" + cell.CellFileName) + "<br>") .AppendLine(" **/"); if (cell.IsPKey) { csharpBuilder.AppendLine(" @Id"); //csharpBuilder.AppendLine(" @GeneratedValue(strategy = GenerationType.IDENTITY)"); } csharpBuilder.AppendLine(" @Column(name = \"" + cell.CellName + "\")") .AppendLine(" private " + cell.CellValueType + " q" + cell.CellName.Replace("q_", "") + ";") .AppendLine(); csharpBuilder .AppendLine(" /**") .AppendLine(" * " + cell.CellNotes + " " + (String.IsNullOrWhiteSpace(cell.CellFileName) ? "" : ("关联文件:" + cell.CellFileName) + "<br>")) .AppendLine(" **/") .AppendLine(" public void setQ" + cell.CellName.Replace("q_", "") + "(" + cell.CellValueType + " q" + cell.CellName.Replace("q_", "") + "){") .AppendLine(" this." + "q" + cell.CellName.Replace("q_", "") + " = q" + cell.CellName.Replace("q_", "") + ";") .AppendLine(" }") .AppendLine(" ") .AppendLine(" ") .AppendLine(" /**") .AppendLine(" * " + cell.CellNotes + " " + (String.IsNullOrWhiteSpace(cell.CellFileName) ? "" : ("关联文件:" + cell.CellFileName) + "<br>")) .AppendLine(" **/") .AppendLine(" public " + cell.CellValueType + " getQ" + cell.CellName.Replace("q_", "") + "() {") .AppendLine(" return this." + "q" + cell.CellName.Replace("q_", "") + ";") .AppendLine(" }") .AppendLine(); } } break; } csharpBuilder.AppendLine("}");// Class End return(csharpBuilder.ToString()); }
string CreateCode(Dictionary <string, ExcelDatas> datas, ExcelDatas model, string strnamespace, Action <string> show, string strspce = " ", bool isCreatenamespace = true) { StringBuilder csharpBuilder = new StringBuilder(); string sheetName = model.SheetName; if (isCreatenamespace) { csharpBuilder.AppendLine("namespace " + strnamespace) .AppendLine("{") .AppendLine() .AppendLine() .AppendLine(strspce + "using System;") .AppendLine(strspce + "using System.Xml.Serialization;") .AppendLine(strspce + "using System.Collections;") .AppendLine(strspce + "using System.Collections.Generic;") .AppendLine(strspce + "using System.Linq;") .AppendLine(strspce + "using System.Text;") .AppendLine(strspce + "using System.Xml;") .AppendLine() .AppendLine(strspce + "/// <summary> ") .AppendLine(strspce + "/// Excel Data To Xml CSharp Class ") .AppendLine(strspce + "/// <para>PS:</para>") .AppendLine(strspce + "/// <para>@author 失足程序员</para>") .AppendLine(strspce + "/// <para>@Blog http://www.cnblogs.com/ty408/</para>") .AppendLine(strspce + "/// <para>@mail [email protected]</para>") .AppendLine(strspce + "/// <para>@phone 13882122019</para>") .AppendLine(strspce + "/// <para> @Create Time " + (DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:sss")) + "</para>") .AppendLine(strspce + "/// </summary>") .AppendLine(strspce + "[XmlRootAttribute(\"" + sheetName + "Manager" + "\")]") .AppendLine(strspce + "public class Q" + sheetName.Replace("q_", "") + "Manager") .AppendLine(strspce + "{") .AppendLine(strspce + " [XmlArray(\"" + sheetName + "\")]") .AppendLine(strspce + " public List<Q" + sheetName.Replace("q_", "") + "> Q" + sheetName.Replace("q_", "") + "s { get; set; }") .AppendLine(strspce + "}") // Class End .AppendLine(); } csharpBuilder.AppendLine(strspce + "[XmlRootAttribute(\"" + sheetName + "" + "\")]") .AppendLine(strspce + "public class Q" + sheetName.Replace("q_", "") + "") .AppendLine(strspce + "{") .AppendLine(); foreach (var row in model.Rows) { var cells = row.Value.Cells; foreach (var cell in cells) { if ("ALL".Equals(cell.Cellgs) || "AC".Equals(cell.Cellgs)) { csharpBuilder .AppendLine(strspce + " /// <summary> ") .AppendLine(strspce + " /// " + cell.CellNotes) .AppendLine(strspce + " /// <pre>" + (string.IsNullOrWhiteSpace(cell.CellFileName) ? "" : "关联文件:" + cell.CellFileName) + "</pre>") .AppendLine(strspce + " /// </summary> ") .AppendLine(strspce + " [XmlAttribute(\"" + cell.CellName + "\")]") .AppendLine(strspce + " public " + cell.CellValueType + " Q" + cell.CellName.Replace("q_", "") + " { get; set; }") .AppendLine(); string dataKey = cell.CellFileName; if (!string.IsNullOrWhiteSpace(dataKey) && datas.ContainsKey(dataKey)) { csharpBuilder .AppendLine(strspce + " [XmlArray(\"" + datas[dataKey].SheetName + "\")]") .AppendLine(strspce + " public List<Q" + datas[dataKey].SheetName.Replace("q_", "") + "> Q" + datas[dataKey].SheetName.Replace("q_", "") + "s { get; set; }") .AppendLine(); } } } break; } csharpBuilder.AppendLine(strspce + "}");// Class End //foreach (var row in model.Rows) //{ // var cells = row.Value.Cells; // foreach (var cell in cells) // { // string dataKey = cell.CellFileName; // if (!string.IsNullOrWhiteSpace(dataKey) && datas.ContainsKey(dataKey)) // { // csharpBuilder.AppendLine(CreateCode(datas, datas[dataKey], strnamespace, show, strspce, false)); // } // } // break; //} if (isCreatenamespace) { csharpBuilder.AppendLine("}");// namespace End } return(csharpBuilder.ToString()); }
string CreateCode(Dictionary <string, ExcelDatas> datas, ExcelDatas model, string strnamespace, Action <string> show, string strspce = " ", bool isCreatenamespace = true) { StringBuilder javaBuilder = new StringBuilder(); string sheetName = model.SheetName; if (isCreatenamespace) { javaBuilder.AppendLine("package " + strnamespace + ";") .AppendLine() .AppendLine() .AppendLine("import java.util.List;") .AppendLine("import java.util.ArrayList;") .AppendLine("import javax.persistence.Column;") .AppendLine("import javax.persistence.Entity;") .AppendLine("import javax.persistence.Id;") .AppendLine("import javax.xml.bind.annotation.XmlRootElement;") .AppendLine("import javax.persistence.Table;") .AppendLine("import javax.persistence.Basic;") .AppendLine() .AppendLine() .AppendLine("/* ") .AppendLine("* Data Source To java Class ") .AppendLine("* ") .AppendLine("* @Create Code Troy.Chen") .AppendLine("* @Phone 13882122019") .AppendLine("* @email [email protected]") .AppendLine("* " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:sss")) .AppendLine("* ") .AppendLine("*/") .AppendLine("[XmlRootAttribute(\"" + sheetName + "" + "\")]") .AppendLine("public class " + sheetName + "") .AppendLine("{") .AppendLine(); } foreach (var row in model.Rows) { var cells = row.Value.Cells; foreach (var cell in cells) { javaBuilder .AppendLine(strspce + " /// <summary> ") .AppendLine(strspce + " /// " + cell.CellNotes) .AppendLine(strspce + " /// <pre>" + (string.IsNullOrWhiteSpace(cell.CellFileName) ? "" : "关联文件:" + cell.CellFileName) + "</pre>") .AppendLine(strspce + " /// </summary> ") .AppendLine(strspce + " [XmlAttribute(\"" + cell.CellName + "\")]") .AppendLine(strspce + " public " + cell.CellValueType + " " + cell.CellName + " { get; set; }") .AppendLine(); string dataKey = cell.CellFileName; if (!string.IsNullOrWhiteSpace(dataKey) && datas.ContainsKey(dataKey)) { javaBuilder .AppendLine(strspce + " [XmlArray(\"" + datas[dataKey].SheetName + "\")]") .AppendLine(strspce + " public List<" + datas[dataKey].SheetName + "> " + datas[dataKey].SheetName + "s { get; set; }") .AppendLine(); } } break; } javaBuilder.AppendLine(strspce + "}");// Class End foreach (var row in model.Rows) { var cells = row.Value.Cells; foreach (var cell in cells) { string dataKey = cell.CellFileName; if (!string.IsNullOrWhiteSpace(dataKey) && datas.ContainsKey(dataKey)) { javaBuilder.AppendLine(CreateCode(datas, datas[dataKey], strnamespace, show, strspce, false)); } } break; } if (isCreatenamespace) { javaBuilder.AppendLine("}");// namespace End } return(javaBuilder.ToString()); }