/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public bool Write(Stream writer, IGenericFile file) { if (writer is null || file is null) { return(false); } try { using (var Doc = WordprocessingDocument.Create(writer, DocumentFormat.OpenXml.WordprocessingDocumentType.Document)) { Doc.PackageProperties.Title = file.Title; Doc.AddMainDocumentPart(); Doc.MainDocumentPart.Document = new Document { Body = new Body() }; if (file is ITable TableFile) { AppendTable(Doc, TableFile); } else { AppendFile(Doc, file); } } } catch { return(false); } return(true); }
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public async Task <bool> WriteAsync(Stream writer, IGenericFile file) { if (writer is null || file is null) { return(false); } var Builder = new StringBuilder(); if (file is ITable FileTable) { Builder.Append(CreateFromTable(FileTable)); } else { Builder.Append(CreateFromFile(file)); } var ByteData = Encoding.UTF8.GetBytes(Builder.ToString()); try { await writer.WriteAsync(ByteData, 0, ByteData.Length).ConfigureAwait(false); } catch { return(false); } return(true); }
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public Task <bool> WriteAsync(Stream writer, IGenericFile file) { if (file is ICard FileCard) { return(WriterCardAsync(writer, FileCard)); } return(Task.FromResult(false)); }
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public bool Write(Stream writer, IGenericFile file) { if (file is ICard FileCard) { return(WriterCard(writer, FileCard)); } return(false); }
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public bool Write(Stream writer, IGenericFile file) { if (file is ICalendar CalendarFile) { WriteCalendar(writer, CalendarFile); return(true); } return(false); }
private void AppendFile(WordprocessingDocument doc, IGenericFile file) { foreach (var ParagraphText in file.ToString().Split('\n')) { doc.MainDocumentPart.Document.Body.Append(new Paragraph( new Run( new Text(ParagraphText)))); } }
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public bool Write(Stream writer, IGenericFile file) { if (file is IFeed FeedFile) { WriteFeed(writer, FeedFile); return(true); } return(false); }
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public async Task <bool> WriteAsync(Stream writer, IGenericFile file) { if (file is IFeed FeedFile) { await WriteFeedAsync(writer, FeedFile).ConfigureAwait(false); return(true); } return(false); }
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public async Task <bool> WriteAsync(Stream writer, IGenericFile file) { if (file is ICalendar CalendarFile) { await WriteCalendarAsync(writer, CalendarFile).ConfigureAwait(false); return(true); } return(false); }
/// <summary> /// Writes the specified data. /// </summary> /// <param name="data">The data.</param> /// <param name="mode">The mode.</param> /// <returns>True if it was written successfully, false otherwise.</returns> public bool Write(IGenericFile data, FileMode mode = FileMode.Create) { var Format = FormatManager?.FindFormat(FullName, Credentials); if (Format is null) { return(false); } using var TempStream = new MemoryStream(); var Success = Format.Write(TempStream, data); Write(TempStream.ReadAllBinary(), mode); return(Success); }
/// <summary> /// Writes the specified data. /// </summary> /// <param name="data">The data.</param> /// <param name="mode">The mode.</param> /// <returns>True if it was written successfully, false otherwise.</returns> public async Task <bool> WriteAsync(IGenericFile data, FileMode mode = FileMode.Create) { var Format = FormatManager?.FindFormat(FullName, Credentials); if (Format is null) { return(false); } using var TempStream = new MemoryStream(); var Success = await Format.WriteAsync(TempStream, data).ConfigureAwait(false); await WriteAsync(await TempStream.ReadAllBinaryAsync().ConfigureAwait(false), mode).ConfigureAwait(false); return(Success); }
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public bool Write(Stream writer, IGenericFile file) { if (writer is null) { return(false); } var TempData = Encoding.UTF8.GetBytes(file?.ToString() ?? ""); try { writer.Write(TempData, 0, TempData.Length); } catch { return(false); } return(true); }
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public async Task <bool> WriteAsync(Stream writer, IGenericFile file) { if (writer is null) { return(false); } var TempData = Encoding.UTF8.GetBytes(file?.ToString() ?? ""); try { await writer.WriteAsync(TempData, 0, TempData.Length).ConfigureAwait(false); } catch { return(false); } return(true); }
/// <summary> /// Writes the specified data. /// </summary> /// <param name="file">The file.</param> /// <param name="data">The data.</param> /// <param name="mimeType">Type of the MIME.</param> /// <returns>True if it was written successfully, false otherwise.</returns> public static bool Write(this Stream file, IGenericFile data, MimeType mimeType) { var Format = InternalManager.FindFormat(file, mimeType); return(Format.Write(file, data)); }
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public bool Write(Stream writer, IGenericFile file) => false;
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public Task <bool> WriteAsync(Stream writer, IGenericFile file) { return(Task.FromResult(Write(writer, file))); }
private string CreateFromFile(IGenericFile file) => "\"" + file?.ToString().Replace("\"", "") + "\"";
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public bool Write(Stream writer, IGenericFile file) => Writer.Write(writer, file);
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public Task <bool> WriteAsync(Stream writer, IGenericFile file) => Writer.WriteAsync(writer, file);
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public bool Write(Stream writer, IGenericFile file) { return(false); }
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public Task <bool> WriteAsync(Stream writer, IGenericFile file) => Task.FromResult(false);
/// <summary> /// Writes the file to the specified writer. /// </summary> /// <param name="writer">The writer.</param> /// <param name="file">The file.</param> /// <returns>True if it writes successfully, false otherwise.</returns> public bool Write(Stream writer, IGenericFile file) { if (writer is null || file is null) { return(false); } try { using var Document = SpreadsheetDocument.Create(writer, SpreadsheetDocumentType.Workbook); Document.AddWorkbookPart(); Document.WorkbookPart.Workbook = new Workbook(); Document.WorkbookPart.Workbook.AppendChild(new Sheets()); var WorksheetPart = InsertSheetInWorksheet(Document.WorkbookPart); var Worksheet = WorksheetPart.Worksheet; var SheetData = Worksheet.GetFirstChild <SheetData>(); if (!(file is ITable TableFile)) { var Row = new Row { RowIndex = 1 }; Row.AppendChild(new Cell { CellValue = new CellValue(file.ToString()), DataType = new EnumValue <CellValues>(CellValues.String), CellReference = "A1" }); SheetData.AppendChild(Row); } else { var headerOffset = 1; if (TableFile.Columns.Count > 0) { headerOffset = 2; var Row = new Row { RowIndex = 1 }; for (var x = 0; x < TableFile.Columns.Count; ++x) { Row.AppendChild(new Cell { CellValue = new CellValue(TableFile.Columns[x]), DataType = new EnumValue <CellValues>(CellValues.String), CellReference = Column(x + 1) + 1 }); } SheetData.AppendChild(Row); } for (var x = 0; x < TableFile.Rows.Count; ++x) { var Row = new Row { RowIndex = (uint)(x + 2) }; SheetData.AppendChild(Row); for (var y = 0; y < TableFile.Rows[x].Cells.Count; ++y) { Row.AppendChild(new Cell { CellValue = new CellValue(TableFile.Rows[x].Cells[y].Content), DataType = new EnumValue <CellValues>(CellValues.String), CellReference = Column(y + 1) + (x + headerOffset) }); } } } }