private dynamic GetSaveOptions(string saveFilePath) { string extension = Path.GetExtension(saveFilePath).Replace(".", ""); extension = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(extension); if (extension.Equals("Txt")) { extension = "Text"; } dynamic options = null; foreach (var item in Enum.GetNames(typeof(WordProcessingFormats))) { if (item.Equals("Auto")) { continue; } if (item.Equals(extension)) { options = new WordProcessingSaveOptions(); break; } } if (options == null) { options = new SpreadsheetSaveOptions(); } return(options); }
public void TestOpenSaveXlsxWithOptions() { // Load var testFile = TestFiles.FourSheetsProtectedXlsx; var loadOptions = new SpreadsheetLoadOptions { FileInfo = testFile.ToFileInfo(), OutputPath = DefaultOutputPath, ExcludeHiddenWorksheets = true }; var loadResult = EditApi.Load(new LoadRequest(loadOptions)); Assert.IsNotEmpty(loadResult.HtmlPath); Assert.IsNotEmpty(loadResult.ResourcesPath); // Save var saveOptions = new SpreadsheetSaveOptions { FileInfo = testFile.ToFileInfo(), HtmlPath = loadResult.HtmlPath, ResourcesPath = loadResult.ResourcesPath, OutputPath = $"{DefaultOutputPath}/{testFile.FileName}", Format = "xlsx", Password = testFile.Password, ProtectionPassword = testFile.Password, ProtectionType = SpreadsheetSaveOptions.ProtectionTypeEnum.All }; var saveResult = EditApi.Save(new SaveRequest(saveOptions)); Assert.AreEqual(saveOptions.OutputPath, saveResult.Path); }
/// <summary> /// Sign spreadsheet and save it to different output type /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Advanced Usage] # SaveSignedSpreadsheetWithDifferentOutputFileType : Sign spreadsheet and save it to different output type\n"); // The path to the documents directory. string filePath = Constants.SAMPLE_SPREADSHEET; string outputFilePath = Path.Combine(Constants.OutputPath, "SaveSignedOutputType", "Sample_XlsxToPdf.pdf"); using (Signature signature = new Signature(filePath)) { // create QRCode option with predefined QRCode text QrCodeSignOptions signOptions = new QrCodeSignOptions("JohnSmith") { // setup QRCode encoding type EncodeType = QrCodeTypes.QR, // set signature position Left = 100, Top = 100 }; SpreadsheetSaveOptions saveOptions = new SpreadsheetSaveOptions() { FileFormat = SpreadsheetSaveFileFormat.Pdf, OverwriteExistingFiles = true }; // sign document to file SignResult result = signature.Sign(outputFilePath, signOptions, saveOptions); Console.WriteLine($"\nSource document signed successfully with {result.Succeeded.Count} signature(s).\nFile saved at {outputFilePath}."); } }
public static void Run() { try { // Create necessary API instances var editApi = new EditApi(Common.GetConfig()); var fileApi = new FileApi(Common.GetConfig()); // The document already uploaded into the storage. // Load it into editable state var loadOptions = new SpreadsheetLoadOptions { FileInfo = new FileInfo { FilePath = "Spreadsheet/four-sheets.xlsx" }, OutputPath = "output", WorksheetIndex = 0 }; var loadResult = editApi.Load(new LoadRequest(loadOptions)); // Download html document var stream = fileApi.DownloadFile(new DownloadFileRequest(loadResult.HtmlPath)); var htmlString = new StreamReader(stream, Encoding.UTF8).ReadToEnd(); // Edit something... htmlString = htmlString.Replace("This is sample sheet", "This is sample sheep"); // Upload html back to storage fileApi.UploadFile(new UploadFileRequest(loadResult.HtmlPath, new MemoryStream(Encoding.UTF8.GetBytes(htmlString)))); // Save html back to xlsx var saveOptions = new SpreadsheetSaveOptions { FileInfo = loadOptions.FileInfo, OutputPath = "output/edited.xlsx", HtmlPath = loadResult.HtmlPath, ResourcesPath = loadResult.ResourcesPath }; var saveResult = editApi.Save(new SaveRequest(saveOptions)); // Done. Console.WriteLine("Document edited: " + saveResult.Path); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } }
private ISaveOptions GetSaveOptions(string guid) { string extension = Path.GetExtension(guid).Replace(".", "").ToLowerInvariant(); ISaveOptions options = null; if (extension.ToLowerInvariant().Equals("txt")) { options = new TextSaveOptions(); } else { foreach (var item in typeof(WordProcessingFormats).GetFields()) { if (item.Name.ToLowerInvariant().Equals("auto")) { continue; } if (item.Name.ToLowerInvariant().Equals(extension)) { WordProcessingFormats format = WordProcessingFormats.FromExtension(extension); options = new WordProcessingSaveOptions(format); break; } } foreach (var item in typeof(PresentationFormats).GetFields()) { if (item.Name.ToLowerInvariant().Equals("auto")) { continue; } if (item.Name.ToLowerInvariant().Equals(extension)) { PresentationFormats format = PresentationFormats.FromExtension(extension); options = new PresentationSaveOptions(format); break; } } if (options == null) { SpreadsheetFormats format = SpreadsheetFormats.FromExtension(extension); options = new SpreadsheetSaveOptions(format); } } return(options); }