Ejemplo n.º 1
0
        private static ExcelData GetData(string path)
        {
            FileStream       stream      = File.Open(path, FileMode.Open, FileAccess.Read);
            IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
            DataSet          dataSet     = excelReader.AsDataSet();
            ExcelData        result      = new ExcelData(dataSet);

            return(result);
        }
Ejemplo n.º 2
0
        public static void ToProtoClass(string path)
        {
            ExcelData data      = GetData(path);
            string    directory = Path.GetDirectoryName(path);

            for (int i = 0; i < data.sheetDatas.Count; i++)
            {
                SheetData sheet     = data.sheetDatas[i];
                ClassData classData = sheet.ToProtoClass();
                string    filePath  = directory + "/" + classData.className + ".cs";
                StringToFile(filePath, classData.classContent);
            }
        }
Ejemplo n.º 3
0
        private static SheetData GetSheet(string path, string sheetName)
        {
            ExcelData data = GetData(path);

            for (int i = 0; i < data.sheetDatas.Count; i++)
            {
                SheetData sheet = data.sheetDatas[i];
                if (sheet.sheetName.Equals(sheetName))
                {
                    return(sheet);
                }
            }
            return(null);
        }
Ejemplo n.º 4
0
        private static SheetData GetSheet(string path, int sheetIndex)
        {
            ExcelData data = GetData(path);

            if (data == null || data.sheetDatas == null || data.sheetDatas.Count < 1)
            {
                return(null);
            }
            if (sheetIndex >= data.sheetDatas.Count)
            {
                return(null);
            }
            return(data.sheetDatas[sheetIndex]);
        }
Ejemplo n.º 5
0
        public static ClassData[] GetFieldClass(string path)
        {
            ExcelData data      = GetData(path);
            string    directory = Path.GetDirectoryName(path);
            int       count     = data.sheetDatas.Count;

            if (count == 0)
            {
                return(null);
            }
            ClassData[] result = new ClassData[count];
            for (int i = 0; i < count; i++)
            {
                SheetData sheet = data.sheetDatas[i];
                result[i] = sheet.ToFieldClass();
            }
            return(result);
        }