예제 #1
0
        private static bool ExportXml(Xlsx xlsx)
        {
            Properties historyProp = MainEntry.XlsxHistory.GetNamespace(xlsx.FileName, false, false);

            if (historyProp == null)
            {
                historyProp = MainEntry.XlsxHistory.Append(xlsx.FileName, xlsx.FileName);
                historyProp.SetString("FilePath", xlsx.RecordInfo.FilePath);
            }
            string fileHash = historyProp.GetString("FileHash", null);

            if (fileHash != xlsx.RecordInfo.FileHash)
            {
                historyProp.SetString("FileHash", xlsx.RecordInfo.FileHash);
                Properties      prop = Properties.CreateFromXlsx(xlsx);
                SecurityElement clientRoot;
                SecurityElement serverRoot;
                Properties.ConvertXlsxPropertiesToXML(prop, out clientRoot, out serverRoot);
                XElement element = XElement.Parse(clientRoot.ToString());
                File.WriteAllText(string.Format("{0}/{1}_client.xml", MakeDir(MainEntry.Config.GetString("xml_dir", null)), xlsx.FileName), element.ToString());
                element = XElement.Parse(serverRoot.ToString());
                File.WriteAllText(string.Format("{0}/{1}_server.xml", MakeDir(MainEntry.Config.GetString("xml_dir", null)), xlsx.FileName), element.ToString());
            }
            return(true);
        }
예제 #2
0
        public static Properties CreateFromXlsx(Xlsx root)
        {
            if (root == null)
            {
                return(null);
            }
            Properties prop = new Properties(root);

            return(prop);
        }
예제 #3
0
 private void ReadProperties(Xlsx root)
 {
     mNamespace = root.FileName;
     mId        = root.FileName;
     foreach (XlsxSheet sheet in root)
     {
         Properties prop = new Properties(sheet, this);
         mNamespaces.Add(prop);
     }
 }
예제 #4
0
        public static Xlsx Create(string filePath)
        {
            FileInfo newFile = new FileInfo(filePath);

            using (ExcelPackage pck = new ExcelPackage(newFile))
            {
                try
                {
                    string name = Path.GetFileNameWithoutExtension(filePath);
                    name = name.Substring(0, 1).ToUpper() + name.Substring(1);
                    ExcelWorkbook workBook = pck.Workbook;
                    if (workBook != null)
                    {
                        Xlsx excel      = new Xlsx(filePath, name);
                        int  cnt        = workBook.Worksheets.Count;
                        var  enumerator = workBook.Worksheets.GetEnumerator();
                        bool isSuccess  = true;
                        while (enumerator.MoveNext())
                        {
                            ExcelWorksheet tDS   = enumerator.Current;
                            XlsxSheet      sheet = XlsxSheet.Create(tDS, excel);
                            if (sheet == null)
                            {
                                isSuccess = false;
                                MainEntry.Log(string.Format("Sheet:{0} failed", tDS.Name));
                                break;
                            }
                            excel.AddSeet(sheet);
                        }
                        if (isSuccess)
                        {
                            return(excel);
                        }
                        MainEntry.Log(string.Format("ExcelWorkbook Failed, Not Parse Sheet Right: {0}", filePath));
                    }
                    else
                    {
                        MainEntry.Log(string.Format("ExcelWorkbook null, Not Parse Right: {0}", filePath));
                    }
                    return(null);
                }
                catch (Exception e)
                {
                    MainEntry.Log(string.Format("ErrorInfo: {0}, StackTrace: {1}, filePath: {2}", e.Message, e.StackTrace, filePath));
                }
            }
            return(null);
        }
예제 #5
0
        private static void TestXlsx()
        {
            string        filePath = "test.xlsx";
            Xlsx          xlsx     = Xlsx.Create(filePath);
            StringBuilder sb       = new StringBuilder();

            xlsx.ExportCSharp(sb);
            File.WriteAllText(string.Format("GameData/{0}.cs", xlsx.FileName), sb.ToString());

            Properties      prop = Properties.CreateFromXlsx(xlsx);
            SecurityElement root = Properties.ConvertPropertiesToXML(prop);
            // 格式化
            XElement element = XElement.Parse(root.ToString());

            File.WriteAllText("xlsx_2_properties_2_xml.xml", element.ToString());
        }
예제 #6
0
        private static bool ExportXlsxFile(string filePath)
        {
            Xlsx xlsx = Xlsx.Create(filePath);

            if (xlsx != null)
            {
                xlsx.InitializeRecord();
                bool res = ExportCS(xlsx);
                res &= ExportXml(xlsx);
                return(res);
            }
            else
            {
                MainEntry.Log(string.Format("ExportXlsxFile Wrong: {0}", filePath));
                return(false);
            }
        }
예제 #7
0
        public static XlsxSheet Create(ExcelWorksheet tDS, Xlsx parent)
        {
            XlsxSheet           sheet = new XlsxSheet(parent, tDS.Name);
            List <string>       variableNames;
            List <DataTypeEnum> variableTypes;
            List <DataSideEnum> variableSides;
            string managerName = null;
            string keys        = null;

            MainEntry.Log(string.Format("-------------------SheetName: {0} Begin", tDS.Name));
            List <XlsxRow> datas = CleanRowAndCols(tDS, sheet, out managerName, out keys, out variableNames, out variableTypes, out variableSides);

            if (datas != null)
            {
                sheet.Set(managerName, keys, variableNames, variableTypes, variableSides, datas);
                MainEntry.Log(string.Format("-------------------SheetName: {0} End", tDS.Name));
                return(sheet);
            }
            MainEntry.Log(string.Format("*******************SheetName: {0} failed", tDS.Name));
            return(null);
        }
예제 #8
0
        private static bool ExportCS(Xlsx xlsx)
        {
            Properties historyProp = MainEntry.XlsxHistory.GetNamespace(xlsx.FileName, false, false);

            if (historyProp == null)
            {
                historyProp = MainEntry.XlsxHistory.Append(xlsx.FileName, xlsx.FileName);
                historyProp.SetString("FilePath", xlsx.RecordInfo.FilePath);
            }
            string sheetHash = historyProp.GetString("SheetHash", null);

            if (sheetHash != xlsx.RecordInfo.SheetHash)
            {
                historyProp.SetString("SheetHash", xlsx.RecordInfo.SheetHash);
                MainEntry.Config.SetString("export_cs", "true");
                StringBuilder builder = new StringBuilder();
                xlsx.ExportCSharp(builder);
                File.WriteAllText(string.Format("{0}/{1}.cs", MakeDir(MainEntry.Config.GetString("cs_dir", null)), xlsx.FileName), builder.ToString());
            }
            return(true);
        }
예제 #9
0
 private XlsxSheet(Xlsx parent, string sheetName)
 {
     Parent    = parent;
     SheetName = sheetName;
 }
예제 #10
0
 private static Properties ConvertXlsxToProperties(Xlsx excel)
 {
     return(Properties.CreateFromXlsx(excel));
 }
예제 #11
0
 private Properties(Xlsx root) : this()
 {
     ReadProperties(root);
     Rewind();
 }