Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //    Test();
            //   return;

            if (args.Length <= 0)
            {
                Console.WriteLine(string.Format("command paramCount {0} must >= 1", args.Length));
                Console.ReadLine();
                return;
            }
            string excelFileName = args[0];

            if (!File.Exists(excelFileName))
            {
                Console.WriteLine(string.Format("Excel File {0} not found~!", excelFileName));
                Console.ReadLine();
                return;
            }
            bool ret = ExcelConvert.ConvertSheet(excelFileName);

            if (ret)
            {
                Console.WriteLine("导出完成");
            }
            else
            {
                Console.WriteLine("导出失败");
            }
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Test()
        {
            string excelFileName = "../../../table/test.xlsx";
            bool   ret           = ExcelConvert.ConvertSheet(excelFileName);

            if (ret)
            {
                Console.WriteLine("导出完成");
            }
            else
            {
                Console.WriteLine("导出失败");
            }
            Console.ReadLine();
        }
Ejemplo n.º 3
0
        public static bool ConvertSheet(string fileName)
        {
            if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
            {
                return(false);
            }
            fileName = Path.GetFullPath(fileName);
            ExcelConvert convert = new ExcelConvert();
            bool         ret     = convert.OpenExcel(fileName);

            if (!ret)
            {
                convert.Dispose();
                return(ret);
            }
            try
            {
                string dir    = Path.GetDirectoryName(fileName);
                var    sheets = convert.GetSheets();
                if (sheets == null)
                {
                    return(false);
                }

                var iter = sheets.GetEnumerator();
                while (iter.MoveNext())
                {
                    var sheet = iter.Current as Microsoft.Office.Interop.Excel.Worksheet;
                    if (sheet != null)
                    {
                        bool isOk = convert.ConvertSheet(sheet, dir);
                        if (!isOk)
                        {
                            string err = string.Format("【Config:{0}】sheet {1} convert error~!", fileName, sheet.Name);
                            Console.WriteLine(err);
                        }
                    }
                }

                return(true);
            } finally
            {
                convert.Dispose();
            }
        }