public static void Run() { // ExStart:1 // The path to the documents directory. string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Open Workbook metadata MetadataOptions options = new MetadataOptions(MetadataType.DocumentProperties); WorkbookMetadata meta = new WorkbookMetadata(dataDir + "Sample1.xlsx", options); // Set some properties meta.CustomDocumentProperties.Add("test", "test"); // Save the metadata info meta.Save(dataDir + "Sample2.out.xlsx"); // Open the workbook Workbook w = new Workbook(dataDir + "Sample2.out.xlsx"); // Read document property Console.WriteLine(w.CustomDocumentProperties["test"]); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); // ExEnd:1 }
public static void Run() { //Source directory string sourceDir = RunExamples.Get_SourceDirectory(); //Output directory string outputDir = RunExamples.Get_OutputDirectory(); // Open Workbook metadata MetadataOptions options = new MetadataOptions(MetadataType.DocumentProperties); WorkbookMetadata meta = new WorkbookMetadata(sourceDir + "sampleUsingWorkbookMetadata.xlsx", options); // Set some properties meta.CustomDocumentProperties.Add("MyTest", "This is My Test"); // Save the metadata info meta.Save(outputDir + "outputUsingWorkbookMetadata.xlsx"); // Open the workbook Workbook w = new Workbook(outputDir + "outputUsingWorkbookMetadata.xlsx"); // Read document property Console.WriteLine("Metadata Custom Property MyTest: " + w.CustomDocumentProperties["MyTest"]); Console.WriteLine("UsingWorkbookMetadata executed successfully."); }
/// <summary> /// Rebuild the crossview sheet /// </summary> /// <param name="application"> /// The excel application object that contains the <see cref="Workbook"/> /// </param> /// <param name="workbook"> /// The current <see cref="Workbook"/> when crossview sheet will be rebuild. /// </param> /// <param name="workbookMetadata"> /// The current <see cref="WorkbookMetadata"/> associated. /// </param> public void Rebuild(Application application, Workbook workbook, WorkbookMetadata workbookMetadata) { var sw = new Stopwatch(); sw.Start(); this.excelApplication = application; this.excelApplication.StatusBar = "Rebuilding Crossview Sheet"; var enabledEvents = application.EnableEvents; var displayAlerts = application.DisplayAlerts; var screenupdating = application.ScreenUpdating; var calculation = application.Calculation; application.EnableEvents = false; application.DisplayAlerts = false; application.Calculation = XlCalculation.xlCalculationManual; application.ScreenUpdating = false; try { application.Cursor = XlMousePointer.xlWait; this.crossviewSheet = CrossviewSheetUtilities.RetrieveSheet(workbook, true); CrossviewSheetUtilities.ApplyLocking(this.crossviewSheet, false); this.PopulateSheetArrays(workbookMetadata.ElementDefinitions, workbookMetadata.ParameterTypes); this.WriteSheet(workbookMetadata.ParameterValues); this.ApplySheetSettings(); CrossviewSheetUtilities.ApplyLocking(this.crossviewSheet, true); this.excelApplication.StatusBar = $"CDP4: Crossview Sheet rebuilt in {sw.ElapsedMilliseconds} [ms]"; } catch (Exception ex) { this.excelApplication.StatusBar = $"CDP4: The following error occured while rebuilding the sheet: {ex.Message}"; throw ex; } finally { application.EnableEvents = enabledEvents; application.DisplayAlerts = displayAlerts; application.Calculation = calculation; application.ScreenUpdating = screenupdating; application.Cursor = XlMousePointer.xlDefault; } }
public static void Main(string[] args) { // The path to the documents directory. string dataDir = Aspose.Cells.Examples.Utils.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); // Open Workbook metadata MetadataOptions options = new MetadataOptions(MetadataType.DocumentProperties); WorkbookMetadata meta = new WorkbookMetadata(dataDir + "Sample1.xlsx", options); // Set some properties meta.CustomDocumentProperties.Add("test", "test"); // Save the metadata info meta.Save(dataDir + "Sample2.xlsx"); // Open the workbook Workbook w = new Workbook(dataDir+ "Sample2.xlsx"); // Read document property Console.WriteLine(w.CustomDocumentProperties["test"]); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); }