예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        IExcelDataReader LoadFromStream(Stream stream, ExcelFileExtension fileType)
        {
            if (fileType == ExcelFileExtension.xlsx)
            {
                return(ExcelReaderFactory.CreateOpenXmlReader(stream));
            }

            return(ExcelReaderFactory.CreateBinaryReader(stream));
        }
예제 #4
0
 /// <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;
 }
예제 #5
0
            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);
        }
예제 #7
0
 IExcelDataReader LoadFromFile(string fileName, ExcelFileExtension fileType)
 => LoadFromStream(new FileStream(fileName, FileMode.Open), fileType);
예제 #8
0
 /// <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
 {
예제 #10
0
 /// <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;
 }
예제 #11
0
 /// <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);