private static bool isValidXLSXFile(byte[] bytFile, String FileContentType) { byte[] chkByteDocx = { 80, 75, 3, 4 }; // Magic Number For Docx bool isvalid = false; ExcelFileExtension docfileExtn = ExcelFileExtension.none; if (FileContentType.Contains("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) { docfileExtn = ExcelFileExtension.XLSX; } if (docfileExtn == ExcelFileExtension.XLSX) { if (bytFile.Length >= 4) { int j = 0; for (Int32 i = 0; i <= 3; i++) { if (bytFile[i] == chkByteDocx[i]) { j = j + 1; if (j == 3) { isvalid = true; } } } } } return(isvalid); }
private static bool isValidXLSFile(byte[] bytFile, String FileContentType) { byte[] chkByteDocx = { 208, 207, 17, 224 }; // Magic Number For Docx bool isvalid = false; ExcelFileExtension docfileExtn = ExcelFileExtension.none; if (FileContentType.Contains("application/vnd.ms-excel")) { docfileExtn = ExcelFileExtension.XLS; } if (docfileExtn == ExcelFileExtension.XLS) { if (bytFile.Length >= 4) { int j = 0; for (Int32 i = 0; i <= 3; i++) { if (bytFile[i] == chkByteDocx[i]) { j = j + 1; if (j == 3) { isvalid = true; } } } } } return(isvalid); }
IExcelDataReader LoadFromStream(Stream stream, ExcelFileExtension fileType) { if (fileType == ExcelFileExtension.xlsx) { return(ExcelReaderFactory.CreateOpenXmlReader(stream)); } return(ExcelReaderFactory.CreateBinaryReader(stream)); }
/// <summary> /// Initialize a new instance of MSToolKit.Core.Mvc.ExcelResult. /// </summary> /// <param name="data">The file's bytes to be attached to the current http response.</param> /// <param name="fileName">(optional)The name, that should be used for the attached file.</param> /// <param name="fileExtension">(optional)The extension, that should be used for the attached file.</param> public ExcelResult( IEnumerable <byte> data, string fileName = DefaultFileName, ExcelFileExtension fileExtension = ExcelFileExtension.xlsx) { this.data = data; this.fileName = fileName; this.fileExtension = fileExtension; }
public ConnectionStringBuilder(string dataSource, string provider, bool hasHeader, ImportExportMode_IMEX?imex = null) { DataSource = dataSource; Provider = provider; ExtendedProperties = new ExtendedProperties(ExcelFileExtension.Version()) { HasHeader = hasHeader, IMEX = imex }; this[nameof(ExtendedPropertiesKey)] = ExtendedProperties.ToCsvString; }
public DataSet GetDataFromExcel(Stream stream, string fileName, bool useHeaderRow) { ExcelFileExtension extension = GetExtension(fileName); using IExcelDataReader excelReader = GetExcelReader(extension, stream); DataSet ds = excelReader.AsDataSet(new ExcelDataSetConfiguration { ConfigureDataTable = (_) => new ExcelDataTableConfiguration { UseHeaderRow = useHeaderRow } }); return(ds); }
IExcelDataReader LoadFromFile(string fileName, ExcelFileExtension fileType) => LoadFromStream(new FileStream(fileName, FileMode.Open), fileType);
/// <summary> /// Information for an excel file /// </summary> /// <param name="excelFile"> The full path of the fail, containing the extension </param> /// <param name="sheetName"> The excel sheet from which the data will be extracted </param> /// <param name="hasHeaders"> Whether the first row of the file contains the column headers </param> /// <param name="selectedColumns"> Which columns to be loaded out of the file </param> public MemorySpreadsheedInfo(Stream fileData, ExcelFileExtension fileType, bool hasHeaders = true, string sheetName = "Sheet1") : base(fileType, hasHeaders, sheetName) { this.FileData = fileData; }
private static IExcelDataReader GetExcelReader(ExcelFileExtension extension, Stream stream) => extension switch {
/// <summary> /// Information for an excel file /// </summary> /// <param name="excelFile"> The full path of the fail, containing the extension </param> /// <param name="sheetName"> The excel sheet from which the data will be extracted </param> /// <param name="hasHeaders"> Whether the first row of the file contains the column headers </param> /// <param name="selectedColumns"> Which columns to be loaded out of the file </param> public SpreadheetInfo(ExcelFileExtension extension = ExcelFileExtension.xls, bool hasHeaders = true, string sheetName = "Sheet1") { this.SheetName = sheetName; this.HasHeaders = hasHeaders; this.Extension = extension; }
/// <summary> /// Returns new instance of MSToolKit.Core.Mvc.ExcelResult. /// </summary> /// <param name="data"> /// The bytes that should be attached to the http response as a excel file. /// </param> /// <param name="fileName"> /// The name, which should be used for the attached file. /// </param> /// <param name="fileExtension"> /// The extension, that should be used for the attached file. /// </param> /// <returns> /// New instance of MSToolKit.Core.Mvc.ExcelResult. /// </returns> protected ExcelResult Excel( IEnumerable <byte> data, string fileName, ExcelFileExtension fileExtension) => new ExcelResult(data, fileName, fileExtension);