public string ValidateMyFile() { int SizeInBytes = MyFileUpload.PostedFile.ContentLength; FileSizeInMB = SizeInBytes / (1024 * 1024); if (FileSizeInMB <= MaxFileSizeInKB) { MyFileType = MyFileUpload.FileName.Substring(MyFileUpload.FileName.LastIndexOf('.')); bool ExtentionSignalStatus = false; foreach (string ext in AllowedExtention) { if (ext.ToUpper() == MyFileType.ToUpper()) { ExtentionSignalStatus = true; break; } } if (ExtentionSignalStatus == true) { // MyFileName = Path.GetRandomFileName() + MyFileType; MyFileName = MyFileUpload.FileName; return("SUCCESS"); } else { return("Invalid File Format."); } } else { return("File size is too large."); } }
public IExport InitExport <TEntity>(IExportSimplePage <TEntity> userPage, MyFileType fileType) { IExport exporter = this.GetExporter <TEntity>(fileType, userPage); exporter.BgExport += new EventHandler <BeginExportEventArgs>(userPage.BeginExport); this.SetWrite(exporter); return(exporter); }
public static IRichTextString GetVersionString(string text, MyFileType fileType = 0) { if (fileType == MyFileType.EXCEL) { return(new XSSFRichTextString(text)); } return(new HSSFRichTextString(text)); }
public void Export(string FileUrl, MyFileType FileType) { if ((FileType != MyFileType.EXCEL) && (FileType != MyFileType.EXCEL2003)) { throw new ExportException("不能导入类型:" + FileType.ToString()); } FileUrl = ExportHelper.GetMatchUrl(FileUrl, FileType); try { byte[] buffer; IWorkbook versionWorkbook = ExportCoreHelper.GetVersionWorkbook(FileType); ExportHelper.CellStyles = new Dictionary <StyleXls, ICellStyle>(); ExportHelper.CellStyles.Add(StyleXls.时间, ExportCoreHelper.GetDateTimeCellStyle(versionWorkbook)); using (MemoryStream stream = new MemoryStream()) { ISheet sheet = versionWorkbook.CreateSheet(); IRow headerRow = sheet.CreateRow(this.HeadRowIndex); this.SetListHead(headerRow); if (this.RowStartIndex == 0) { this.RowStartIndex = this.HeadRowIndex + 1; } int rowStartIndex = this.RowStartIndex; foreach (T local in base.DataSource) { IRow row2 = sheet.CreateRow(rowStartIndex); int columnStartIndex = this.ColumnStartIndex; foreach (PropertyInfo info in this.HeadSupport.Values) { ICell exCell = row2.CreateCell(columnStartIndex); if (info == null) { exCell.SetCellValue(""); } else { object obj2 = info.GetValue(local, null); ExportHelper.SetCellValue(exCell, obj2, info.PropertyType.Name); } columnStartIndex++; } rowStartIndex++; } //AutoSizeColumns(sheet); versionWorkbook.Write(stream); buffer = stream.ToArray(); } using (FileStream stream2 = new FileStream(FileUrl, FileMode.Create, FileAccess.Write)) { stream2.Write(buffer, 0, buffer.Length); Console.WriteLine("文件导出成功!" + FileUrl); } } catch (Exception exception) { throw new ExportException(exception.Message); } }
public void Export(string fileUrl, MyFileType fileType) { fileUrl = ExportHelper.GetMatchUrl(fileUrl, fileType); byte[] buffer = base.Export <TEntity>(this.DataSource, fileType); using (FileStream stream = new FileStream(fileUrl, FileMode.Create, FileAccess.Write)) { stream.Write(buffer, 0, buffer.Length); Console.WriteLine("文件导出成功!" + fileUrl); } }
public static IWorkbook GetVersionWorkbook(MyFileType fileType) { switch (fileType) { case MyFileType.EXCEL: return(new XSSFWorkbook()); case MyFileType.EXCEL2003: return(new HSSFWorkbook()); } return(new XSSFWorkbook()); }
public void Add(string extension) { // Add the following extension properties into the internal // dictionary. If it is already there, we will not do anything if (_fileTypes.ContainsKey(extension)) { return; } // Not found, get the file info for this extension from the system // Get a dummy file name string dummyFileName = Path.ChangeExtension(@"C:\Dummy", extension); SHFILEINFO shinfo = new SHFILEINFO(); SHGFI flags = SHGFI.SHGFI_ICON | SHGFI.SHGFI_SMALLICON | SHGFI.SHGFI_USEFILEATTRIBUTES | SHGFI.SHGFI_TYPENAME; IntPtr ret = SHGetFileInfo( dummyFileName, string.Compare(extension, DiretoryType, StringComparison.OrdinalIgnoreCase) == 0 ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL, ref shinfo, Marshal.SizeOf(shinfo), flags); // The icon is returned in the hIcon member of the shinfo struct. MyFileType fileType = new MyFileType(); if (ret != IntPtr.Zero) { fileType.Description = shinfo.szTypeName; if (shinfo.hIcon != IntPtr.Zero) { _imageList.Images.Add(Icon.FromHandle(shinfo.hIcon)); fileType.ImageIndex = _imageList.Images.Count - 1; } else { fileType.ImageIndex = -1; } } else { fileType.Description = "Unknown"; fileType.ImageIndex = -1; } // Add it to the dictionary _fileTypes.Add(extension, fileType); }
public void Export(string FileUrl, MyFileType FileType) { FileUrl = ExportHelper.GetMatchUrl(FileUrl, FileType); Report report = new Report(base.DataSource.ToList <T>().ToReportSource()) { TextFields = { Title = "产品报表", SubTitle = "这是一个测试DoddleReport的导出文件", Footer = "测试于2014-1-10", Header = string.Format(" 产品报表表头", new object[0]) }, RenderHints = { BooleanCheckboxes = true } }; using (FileStream stream = File.Create(FileUrl)) { this.GetWriter(FileType).WriteReport(report, stream); Console.WriteLine("文件导出成功!" + FileUrl); } }
private IExport GetExporter <TEntity>(MyFileType fileType, IExportSimplePage <TEntity> userPage) { switch (fileType) { case MyFileType.EXCEL: case MyFileType.EXCEL2003: return(new NPOIExport <TEntity>(userPage.GetDataSource(), userPage.GetHead())); case MyFileType.PDF: case MyFileType.CSV: case MyFileType.HTML: case MyFileType.TXT: return(new DoddleReportExport <TEntity>(userPage.GetDataSource(), userPage.GetHead())); } return(new NPOIExport <TEntity>(userPage.GetDataSource(), userPage.GetHead())); }
private IReportWriter GetWriter(MyFileType fileType) { switch (fileType) { case MyFileType.CSV: return(new DelimitedTextReportWriter()); case MyFileType.HTML: return(new HtmlReportWriter()); case MyFileType.TXT: return(new DelimitedTextReportWriter()); case MyFileType.EXCEL2003: return(new ExcelReportWriter()); } return(new ExcelReportWriter()); }
public static string GetMatchUrl(string fileUrl, MyFileType fileType) { switch (fileType) { case MyFileType.EXCEL: return(SetMatchUrl(fileUrl, "xlsx")); case MyFileType.PDF: return(SetMatchUrl(fileUrl, "pdf")); case MyFileType.CSV: return(SetMatchUrl(fileUrl, "csv")); case MyFileType.HTML: return(SetMatchUrl(fileUrl, "html")); case MyFileType.TXT: return(SetMatchUrl(fileUrl, "txt")); case MyFileType.EXCEL2003: return(SetMatchUrl(fileUrl, "xls")); } return(SetMatchUrl(fileUrl, "xlsx")); }
public byte[] GetFile(MyFileType fileType) { return(new byte[0]); }
public byte[] GetFile(MyFileType fileType) { return(base.Export <TEntity>(this.DataSource, fileType)); }
protected byte[] Export <T>(IList <T> DataSource, MyFileType fileType) { if ((fileType != MyFileType.EXCEL) && (fileType != MyFileType.EXCEL2003)) { throw new ExportException("不能导出类型" + fileType.ToString()); } int columnStartIndex = this.ColumnStartIndex; foreach (string str in this.Head) { this.defineLocation.Add(str, columnStartIndex); columnStartIndex++; } ExportHelper.headStyles = new Dictionary <string, ICellStyle>(); List <string> sheetName = new List <string>(); Dictionary <int, int> columnWidth = new Dictionary <int, int>(); BeginExportEventArgs e = new BeginExportEventArgs(sheetName, this.defineLocation, columnWidth); this.BeginExport(e); this.CurWorkBook = ExportCoreHelper.GetVersionWorkbook(fileType); ExportHelper.CellStyles = new Dictionary <StyleXls, ICellStyle>(); ExportHelper.CellStyles.Add(StyleXls.默认, ExportCoreHelper.Getcellstyle(CurWorkBook, StyleXls.默认)); ExportHelper.CellStyles.Add(StyleXls.时间, ExportCoreHelper.Getcellstyle(CurWorkBook, StyleXls.时间)); ExportHelper.CellStyles.Add(StyleXls.数字, ExportCoreHelper.Getcellstyle(CurWorkBook, StyleXls.数字)); if (this.RowStartIndex == 0) { this.RowStartIndex = this.HeadRowIndex + 1; } if (sheetName.Count == 0) { sheetName.Add("sheet1"); } using (MemoryStream stream = new MemoryStream()) { foreach (string str2 in sheetName) { ISheet sheet = this.CurWorkBook.CreateSheet(str2); foreach (string str3 in this.defineLocation.Keys) { int key = this.defineLocation[str3]; if (columnWidth.ContainsKey(key)) { sheet.SetColumnWidth(key, columnWidth[key] * 50); } else { int num3 = StringHelper.trueLength(str3); if (num3 > 14) { sheet.SetColumnWidth(key, 330 * num3); } else { sheet.SetColumnWidth(key, 0x1130); } } } this.SetListHead(sheet); this.SetListData(sheet); //AutoSizeColumns(sheet); } this.CurWorkBook.Write(stream); return(stream.ToArray()); } }