public static MarkDownTable ToMd(this string xls, string sheet) { FileStream stream=File.Open(xls, FileMode.Open, FileAccess.Read); IExcelDataReader excelReader=null; if (Path.GetExtension(xls)==".xls") { excelReader=ExcelReaderFactory.CreateBinaryReader(stream); } else if (Path.GetExtension(xls)==".xlsx") { excelReader=ExcelReaderFactory.CreateOpenXmlReader(stream); } else { throw new ArgumentException("Not Support Format: "); } DataSet dataSet=excelReader.AsDataSet(); DataTable dataTable=dataSet.Tables[sheet]; var table=new MarkDownTable { Name=dataTable.TableName, Value=dataTable.ToMd() }; excelReader.Close(); return table; }
public static MarkDownTable XlsToMd(this string xls, string sheet) { FileStream stream = File.Open(xls, FileMode.Open, FileAccess.Read); IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream); DataSet dataSet = excelReader.AsDataSet(); DataTable dataTable = dataSet.Tables[sheet]; var table = new MarkDownTable { Name = dataTable.TableName, Value = dataTable.ToMd() }; excelReader.Close(); return table; }