public static void Run() { try { // Create necessary API instances var apiInstance = new ConvertApi(Constants.GetConfig()); // Prepare convert settings var loadOptions = new SpreadsheetLoadOptions { SkipEmptyRowsAndColumns = true, OnePagePerSheet = true }; var settings = new ConvertSettings { StorageName = Constants.MyStorage, FilePath = "Spreadsheet/sample.xlsx", Format = "pdf", LoadOptions = loadOptions, OutputPath = "converted" }; // Convert to specified format var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings)); Console.WriteLine("Document converted successfully: " + response[0].Url); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } }
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); }
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 static ILoadOptions GetLoadOptions(string guid) { string extension = Path.GetExtension(guid).Replace(".", "").ToLowerInvariant(); ILoadOptions options = null; foreach (var item in typeof(WordProcessingFormats).GetFields()) { if (item.Name.ToLowerInvariant().Equals("auto")) { continue; } if (item.Name.ToLowerInvariant().Equals(extension)) { options = new WordProcessingLoadOptions(); break; } } foreach (var item in typeof(PresentationFormats).GetFields()) { if (item.Name.ToLowerInvariant().Equals("auto")) { continue; } if (item.Name.ToLowerInvariant().Equals(extension)) { options = new PresentationLoadOptions(); break; } } foreach (var item in typeof(SpreadsheetFormats).GetFields()) { if (item.Name.ToLowerInvariant().Equals("auto")) { continue; } if (item.Name.ToLowerInvariant().Equals(extension)) { options = new SpreadsheetLoadOptions(); break; } } return(options); }
public static void Run() { try { // Create necessary API instances var apiInstance = new ConvertApi(Constants.GetConfig()); // Prepare convert settings var loadOptions = new SpreadsheetLoadOptions { DefaultFont = "Helvetica", FontSubstitutes = new Dictionary <string, string> { { "Tahoma", "Arial" }, { "Times New Roman", "Arial" } }, OnePagePerSheet = true }; var settings = new ConvertSettings { StorageName = Constants.MyStorage, FilePath = "Spreadsheet/sample.xlsx", Format = "pdf", LoadOptions = loadOptions, OutputPath = "converted" }; // Convert to specified format var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings)); Console.WriteLine("Document converted successfully: " + response[0].Url); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); } }