public void Load(string path, IO.FileFormat fileFormat, Encoding encoding) { if (fileFormat == IO.FileFormat._Auto) { foreach (var p in FileFormatProviders) { if (p.Value.IsValidFormat(path)) { fileFormat = p.Key; break; } } if (fileFormat == FileFormat._Auto) { throw new NotSupportedException("Cannot determine the file format to load workbook from specified path, try specify explicitly the file format by argument."); } } using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { this.Load(fs, fileFormat, encoding == null ? Encoding.Default : encoding); } // for csv only if (fileFormat == FileFormat.CSV) { if (this.worksheets.Count > 0) { this.worksheets[0].Name = Path.GetFileNameWithoutExtension(path); } } }
public void Save(System.IO.Stream stream, IO.FileFormat fileFormat, Encoding encoding) { IFileFormatProvider provider = null; if (!FileFormatProviders.TryGetValue(fileFormat, out provider)) { throw new FileFormatNotSupportException("Specified file format is not supported"); } if (this.controlAdapter != null) { this.controlAdapter.ChangeCursor(CursorStyle.Busy); } try { provider.Save(this, stream, encoding, null); } finally { if (this.controlAdapter != null) { this.controlAdapter.ChangeCursor(CursorStyle.PlatformDefault); } if (this.WorkbookSaved != null) { this.WorkbookSaved(this, null); } } }
public void Save(string path, IO.FileFormat fileFormat, Encoding encoding, object arg = null) { if (fileFormat == IO.FileFormat._Auto) { foreach (var p in FileFormatProviders) { if (p.Value.IsValidFormat(path)) { fileFormat = p.Key; break; } } if (fileFormat == FileFormat._Auto) { throw new NotSupportedException("Cannot determine a file format to load workbook from specified path, try specify the file format."); } } if (fileFormat == FileFormat.Excel2007) { var ext = Path.GetExtension(path); if (ext.Equals(".xlsx", StringComparison.InvariantCultureIgnoreCase)) { arg = IO.OpenXML.Schema.OpenXMLContentTypes.Workbook______; } else if (ext.Equals(".xltx", StringComparison.InvariantCultureIgnoreCase)) { arg = IO.OpenXML.Schema.OpenXMLContentTypes.Template______; } if (ext.Equals(".xlsm", StringComparison.InvariantCultureIgnoreCase)) { arg = IO.OpenXML.Schema.OpenXMLContentTypes.MacroWorkbook_; } else if (ext.Equals(".xltm", StringComparison.InvariantCultureIgnoreCase)) { arg = IO.OpenXML.Schema.OpenXMLContentTypes.MacroTemplate_; } } var temp = Path.GetTempFileName(); try { using (var fs = new FileStream(temp, FileMode.Create, FileAccess.ReadWrite)) { Save(fs, fileFormat, encoding, arg); } File.Copy(temp, path, true); } finally { File.Delete(temp); } }
public object Load(System.IO.Stream stream, IO.FileFormat fileFormat, Encoding encoding, object arg) { object ret = null; if (fileFormat == FileFormat._Auto) { throw new System.ArgumentException("File format 'Auto' is invalid for loading workbook from stream, try specify a file format."); } IFileFormatProvider provider = null; if (!FileFormatProviders.TryGetValue(fileFormat, out provider)) { throw new FileFormatNotSupportException("Specified file format is not supported."); } if (this.controlAdapter != null) { this.controlAdapter.ChangeCursor(CursorStyle.Busy); } if (encoding == null) { encoding = Encoding.Default; } try { ret = provider.Load(this, stream, encoding, arg); Recalculate(); ExpandToContent(); } finally { if (controlAdapter != null) { controlAdapter.ChangeCursor(CursorStyle.PlatformDefault); } WorkbookLoaded?.Invoke(this, null); } return(ret); }
public void Load(System.IO.Stream stream, IO.FileFormat fileFormat, Encoding encoding, string singleSheet = "") { if (fileFormat == FileFormat._Auto) { throw new System.ArgumentException("File format 'Auto' is invalid for loading workbook from stream, try specify a file format."); } IFileFormatProvider provider = null; if (!FileFormatProviders.TryGetValue(fileFormat, out provider)) { throw new FileFormatNotSupportException("Specified file format is not supported."); } if (this.controlAdapter != null) { this.controlAdapter.ChangeCursor(CursorStyle.Busy); } if (encoding == null) { encoding = Encoding.Default; } try { provider.Load(this, stream, encoding, null, singleSheet); } finally { if (this.controlAdapter != null) { this.controlAdapter.ChangeCursor(CursorStyle.PlatformDefault); } this.WorkbookLoaded?.Invoke(this, null); } }
public void Save(string path, IO.FileFormat fileFormat, Encoding encoding) { if (fileFormat == IO.FileFormat._Auto) { foreach (var p in FileFormatProviders) { if (p.Value.IsValidFormat(path)) { fileFormat = p.Key; break; } } if (fileFormat == FileFormat._Auto) { throw new NotSupportedException("Cannot determine a file format to load workbook from specified path, try specify the file format."); } } using (var fs = new FileStream(path, FileMode.Create, FileAccess.Write)) { Save(fs, fileFormat, encoding); } }
public void Load(System.IO.Stream stream, IO.FileFormat fileFormat) { this.Load(stream, fileFormat, Encoding.Default); }
public void Load(string path, IO.FileFormat fileFormat) { this.Load(path, fileFormat, Encoding.Default); }
public void Save(string path, IO.FileFormat fileFormat) { this.Save(path, fileFormat, Encoding.Default); }
public void Load(System.IO.Stream stream, IO.FileFormat fileFormat, string singleSheet = "") { this.Load(stream, fileFormat, Encoding.Default, singleSheet); }
public void Load(string path, IO.FileFormat fileFormat, string singleSheet = "") { this.Load(path, fileFormat, Encoding.Default, singleSheet); }
public object Load(System.IO.Stream stream, IO.FileFormat fileFormat, object arg) { return(Load(stream, fileFormat, Encoding.Default, arg)); }
public object Load(string path, IO.FileFormat fileFormat, object arg = null) { return(Load(path, fileFormat, Encoding.Default, arg)); }
public void Save(System.IO.Stream stream, IO.FileFormat fileFormat, object arg = null) { Save(stream, fileFormat, Encoding.Default, arg); }
public void Save(string path, IO.FileFormat fileFormat, object arg = null) { Save(path, fileFormat, Encoding.Default, arg); }