WorkbookMetadata.Save

Save(string)

Save the modified metadata to the file.

public void Save(string fileName)
ParameterTypeDescription
fileNameStringThe file name.

Examples

using System;
using Aspose.Cells;
using Aspose.Cells.Metadata;

namespace AsposeCellsExamples
{
    public class WorkbookMetadataMethodSaveWithStringDemo
    {
        public static void Run()
        {
            // Create a new workbook metadata
            WorkbookMetadata doc = new WorkbookMetadata("example.xlsb", new MetadataOptions(Aspose.Cells.Metadata.MetadataType.DocumentProperties));
            
            // Add custom properties
            doc.CustomDocumentProperties.Add("text1", "text2");
            doc.CustomDocumentProperties.Add("num1", 1);
            
            // Save with string path
            doc.Save("output.xlsb");
            
            // Verify the saved file
            Workbook workbook = new Workbook("output.xlsb");
            Console.WriteLine("File saved successfully with custom properties.");
            Console.WriteLine("Property 'text1' value: " + doc.CustomDocumentProperties["text1"].Value.ToString());
        }
    }
}

See Also


Save(Stream)

Save the modified metadata to the stream.

public void Save(Stream stream)
ParameterTypeDescription
streamStreamThe stream.

Examples

namespace AsposeCellsExamples
{
    using System;
    using System.IO;
    using Aspose.Cells;
    using Aspose.Cells.Metadata;

    public class WorkbookMetadataMethodSaveWithStreamDemo
    {
        public static void Run()
        {
            try
            {
                // Path to an existing workbook (ensure the file exists in the execution folder)
                string sourcePath = "Sample.xlsx";

                // Create MetadataOptions for document properties
                MetadataOptions options = new MetadataOptions(MetadataType.DocumentProperties);

                // Instantiate WorkbookMetadata with the source file and options
                WorkbookMetadata metadata = new WorkbookMetadata(sourcePath, options);

                // Access the built‑in document properties collection (read‑only)
                var builtInProperties = metadata.BuiltInDocumentProperties;
                Console.WriteLine("Built‑in document properties collection retrieved.");

                // Save the metadata to a new file using a stream
                using (FileStream outputStream = new FileStream("MetadataOutput.xlsx",
                                                              FileMode.Create,
                                                              FileAccess.Write))
                {
                    metadata.Save(outputStream);
                }

                Console.WriteLine("Metadata saved successfully to stream.");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error during metadata Save: {ex.Message}");
            }
        }
    }
}

See Also