### Install unioffice Source: https://github.com/esword618/unioffice/blob/main/README.md Install the unioffice library using the go get command. This command fetches and installs the latest version of the package. ```bash go get -u github.com/Esword618/unioffice ``` -------------------------------- ### Creating a Presentation Source: https://github.com/esword618/unioffice/blob/main/_autodocs/README.md Example demonstrating how to create a new PowerPoint presentation and save it to a file. ```APIDOC ## Creating a Presentation ### Description This example shows the basic steps to create a new PowerPoint presentation using the `presentation` package and save it to a file. ### Method ```go New() AddSlide() SaveToFile(filename string) ``` ### Parameters - `presentation.New()`: No parameters. - `pres.AddSlide()`: No parameters. - `pres.SaveToFile(filename string)`: `filename` (string) - The path to save the PowerPoint presentation. ### Request Example ```go import "github.com/Esword618/unioffice/presentation" pres := presentation.New() slide := pres.AddSlide() pres.SaveToFile("output.pptx") ``` ### Response - The `SaveToFile` method does not return a value upon success. Errors during file saving would typically be handled by the Go runtime. ``` -------------------------------- ### Distance Example Source: https://github.com/esword618/unioffice/blob/main/_autodocs/types.md Example of creating Distance variables using inch and centimeter units. ```go width := 2.5 * measurement.Inch height := 1 * measurement.Cm ``` -------------------------------- ### Build unioffice Source: https://github.com/esword618/unioffice/blob/main/README.md Build the unioffice library and its dependencies using the go build command. The -i flag installs the packages. ```bash go build -i github.com/Esword618/unioffice/... ``` -------------------------------- ### Creating a Spreadsheet Source: https://github.com/esword618/unioffice/blob/main/_autodocs/README.md Example demonstrating how to create a new Excel spreadsheet, add data to cells, and save it to a file. ```APIDOC ## Creating a Spreadsheet ### Description This example illustrates how to create a new Excel workbook and sheet using the `spreadsheet` package. It shows how to set cell values and save the workbook. ### Method ```go New() AddSheet() Cell(address string) SetString(value string) SetNumber(value float64) SaveToFile(filename string) ``` ### Parameters - `spreadsheet.New()`: No parameters. - `wb.AddSheet()`: No parameters. - `sheet.Cell(address string)`: `address` (string) - The cell address (e.g., "A1"). - `cell.SetString(value string)`: `value` (string) - The string value to set for the cell. - `cell.SetNumber(value float64)`: `value` (float64) - The numeric value to set for the cell. - `wb.SaveToFile(filename string)`: `filename` (string) - The path to save the Excel spreadsheet. ### Request Example ```go import "github.com/Esword618/unioffice/spreadsheet" wb := spreadsheet.New() sheet := wb.AddSheet() sheet.Cell("A1").SetString("Name") sheet.Cell("B1").SetString("Age") sheet.Cell("A2").SetString("John") sheet.Cell("B2").SetNumber(30) wb.SaveToFile("output.xlsx") ``` ### Response - The `SaveToFile` method does not return a value upon success. Errors during file saving would typically be handled by the Go runtime. ``` -------------------------------- ### Create a New Presentation Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Use `presentation.New()` to create an empty presentation object. This is the starting point for building a new .pptx file. ```Go import "github.com/Esword618/unioffice/presentation" pres := presentation.New() slide := pres.AddSlide() // Add content to slide pres.SaveToFile("output.pptx") ``` -------------------------------- ### Creating a Word Document Source: https://github.com/esword618/unioffice/blob/main/_autodocs/README.md Example demonstrating how to create a new Word document, add a paragraph with text, and save it to a file. ```APIDOC ## Creating a Word Document ### Description This example shows the basic steps to create a new Word document using the `document` package. It includes adding a paragraph, a text run, and saving the document. ### Method ```go New() AddParagraph() AddRun() AddText(text string) SaveToFile(filename string) ``` ### Parameters - `document.New()`: No parameters. - `doc.AddParagraph()`: No parameters. - `para.AddRun()`: No parameters. - `run.AddText(text string)`: `text` (string) - The text content to add to the run. - `doc.SaveToFile(filename string)`: `filename` (string) - The path to save the Word document. ### Request Example ```go import "github.com/Esword618/unioffice/document" doc := document.New() para := doc.AddParagraph() run := para.AddRun() run.AddText("Hello, World!") doc.SaveToFile("output.docx") ``` ### Response - The `SaveToFile` method does not return a value upon success. Errors during file saving would typically be handled by the Go runtime. ``` -------------------------------- ### spreadsheet.New Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet.md Creates a new, empty Workbook instance. This is the starting point for creating new Excel files. ```APIDOC ## spreadsheet.New ### Description Creates a new empty workbook ready for sheets and content to be added. ### Method func ### Parameters None ### Returns - `*Workbook` — A new empty Workbook with default styles and properties ### Example ```go import "github.com/Esword618/unioffice/spreadsheet" wb := spreadsheet.New() sheet := wb.AddSheet() sheet.Cell("A1").SetString("Hello") sheet.Cell("B1").SetString("World") wb.SaveToFile("output.xlsx") ``` ``` -------------------------------- ### Document Text Formatting Example Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Demonstrates creating a document, adding paragraphs, and applying various text formatting properties like bold, size, color, and alignment to runs. ```go doc := document.New() para := doc.AddParagraph() para.SetStyle("Heading1") props := para.Properties() props.SetAlignment(wml.ST_JcCenter) run := para.AddRun() run.AddText("Chapter 1") rProps := run.Properties() rProps.SetBold(true) rProps.SetSize(28) // 14pt rProps.SetColor(color.Blue) para2 := doc.AddParagraph() run2 := para2.AddRun() run2.AddText("This is ") rProps2 := run2.Properties() rProps2.SetSize(22) // 11pt run3 := para2.AddRun() run3.AddText("bold text") run3.Properties().SetBold(true) run3.Properties().SetColor(color.Red) run4 := para2.AddRun() run4.AddText(" with normal text.") run4.Properties().SetSize(22) ``` -------------------------------- ### New Presentation Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Creates a new, empty PowerPoint presentation. This is the starting point for building a presentation programmatically. ```APIDOC ## New Creates a new empty presentation ready for slides to be added. ### Description Initializes a new `Presentation` object with a default slide master and layout, prepared for adding slides and content. ### Method `New()` ### Returns - `*Presentation` — A pointer to a new, empty `Presentation` object. ### Example ```go import "github.com/Esword618/unioffice/presentation" pres := presentation.New() slide := pres.AddSlide() // Add content to slide pres.SaveToFile("output.pptx") ``` ``` -------------------------------- ### Convert Measurements to Inches Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MODULE-STRUCTURE.md Example of using the measurement package to define dimensions in inches for document elements. ```go import "github.com/Esword618/unioffice/measurement" width := 8.5 * measurement.Inch height := 11 * measurement.Inch ``` -------------------------------- ### Handle Spreadsheet Sheet Not Found Error Source: https://github.com/esword618/unioffice/blob/main/_autodocs/README.md Demonstrates how to get a spreadsheet sheet and handle the case where it is not found by adding it. ```go sheet, err := wb.GetSheet("Data") if err == spreadsheet.ErrorNotFound { sheet = wb.AddSheet() } ``` -------------------------------- ### Handle Document Save Errors Source: https://github.com/esword618/unioffice/blob/main/_autodocs/README.md Provides an example of saving a document to a file and handling potential errors. ```go if err := doc.SaveToFile("output.docx"); err != nil { log.Fatalf("Failed to save: %v", err) } ``` -------------------------------- ### Get All Placeholders in Slide Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Returns a slice containing all placeholder shapes present in the slide. ```go for _, ph := range slide.PlaceHolders() { fmt.Println(ph.Name()) } ``` -------------------------------- ### Get All Tables Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet.md Retrieves a slice containing all tables defined across all sheets within the workbook. ```go func (wb *Workbook) Tables() []Table ``` -------------------------------- ### Get All Headers in Document Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document.md Retrieves all headers that have been defined within the document. Returns a slice of Header objects. ```go func (d *Document) Headers() []Header ``` -------------------------------- ### New Document Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document.md Creates a new, empty Word document ready for content to be added. This is the starting point for creating any document. ```APIDOC ## New Document ### Description Creates an empty document ready for content to be added. ### Method func New() *Document ### Parameters None ### Returns *Document — A new empty Document with initialized properties ### Example ```go import "github.com/Esword618/unioffice/document" doc := document.New() para := doc.AddParagraph() run := para.AddRun() run.AddText("Hello, World!") doc.SaveToFile("output.docx") ``` ``` -------------------------------- ### Get All Footers in Document Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document.md Retrieves all footers that have been defined within the document. Returns a slice of Footer objects. ```go func (d *Document) Footers() []Footer ``` -------------------------------- ### Get Underlying Slide XML Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Returns the underlying XML representation of the slide as a *pml.Sld object. ```go func (s Slide) X() *pml.Sld ``` -------------------------------- ### Get Placeholder by Type Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Retrieves a placeholder of a specific type, such as title or content. Returns the first matching placeholder and an error if none is found. ```go titlePh, err := slide.GetPlaceholder(pml.ST_PlaceholderTypeTit) if err != nil { log.Fatal(err) } ``` -------------------------------- ### Get or Create Custom Properties Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Returns the presentation's custom properties, creating them if they do not exist. The returned CustomProperties object can be modified and saved. ```go func (p *Presentation) GetOrCreateCustomProperties() common.CustomProperties ``` -------------------------------- ### Retrieve Current License Key Configuration Source: https://github.com/esword618/unioffice/blob/main/_autodocs/configuration.md Get the currently configured license key details. This function returns a `LicenseKey` struct, which can be `nil` if no license is set, or a default unlicensed key. ```go lk := license.GetLicenseKey() fmt.Println(lk.TypeToString()) fmt.Println("Licensed:", lk.IsLicensed()) ``` -------------------------------- ### Retrieve All Slide Layouts Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Get all available slide layouts in the presentation using `pres.SlideLayouts()`. This is useful for selecting a layout when adding new slides. ```Go for _, layout := range pres.SlideLayouts() { fmt.Println(layout.Name()) } ``` -------------------------------- ### Get or Create Custom Document Properties Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document.md Retrieves the document's custom properties. If they do not exist, they are created. Returns a common.CustomProperties object. ```go func (d *Document) GetOrCreateCustomProperties() common.CustomProperties ``` -------------------------------- ### Get Sheet by Name Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet.md Retrieves a specific sheet from the workbook using its name. An error is returned if a sheet with the provided name is not found. ```Go sheet, err := wb.GetSheet("Data") if err != nil { log.Fatal(err) } ``` -------------------------------- ### Get Workbook Protection Settings Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet.md Retrieves the current workbook protection settings. This object can be used to inspect or modify protection. ```go func (wb *Workbook) Protection() WorkbookProtection ``` -------------------------------- ### Get Run Text Content Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Retrieves the complete text content of a run. This combines any text segments added to the run. ```Go text := run.Text() ``` -------------------------------- ### Configure Run Properties Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Get and modify run properties to apply formatting like bold, italic, size, and color to text. This is useful for styling specific segments of text within a document. ```go props := run.Properties() props.SetBold(true) props.SetItalic(true) props.SetSize(24) props.SetColor(color.Red) ``` -------------------------------- ### Get Image by Relationship ID Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Retrieves an image by its relationship ID. Returns the image reference and a boolean indicating if the image was found. ```go func (p *Presentation) GetImageByRelID(relID string) (common.ImageRef, bool) ``` -------------------------------- ### Access Low-Level XML Types Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MODULE-STRUCTURE.md Use the X() method on main types to get direct access to the underlying OOXML structure for advanced manipulation. ```go doc := document.New() // High-level API para := doc.AddParagraph() // Low-level XML access xmlDoc := doc.X() // *wml.Document ``` -------------------------------- ### Get Placeholder by Index Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Retrieves a placeholder from a slide using its index. Ensure the index is within the valid range of placeholders on the slide. ```go func (s Slide) GetPlaceholderByIndex(idx uint32) (PlaceHolder, error) ``` -------------------------------- ### Get Formatted Cell Value Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet-cell-row.md Use GetFormattedValue to get the cell's value as a string, formatted as it would appear in Excel (e.g., "42.50%" instead of 0.425). ```go formatted := cell.GetFormattedValue() // e.g., "42.50%" instead of 0.425 ``` -------------------------------- ### Get Underlying XML Presentation Structure Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Access the raw OOXML presentation structure using `pres.X()`. This method returns a pointer to the `pml.Presentation` type. ```Go func (p *Presentation) X() *pml.Presentation ``` -------------------------------- ### Get Cell Column Letter Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet-cell-row.md Use Column() to get the column letter (e.g., "A", "AA") for a given cell. An error is returned if the cell reference is invalid. ```go col, err := cell.Column() // "A" for cell A1 ``` -------------------------------- ### Get or Create Cell in a Row Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet-cell-row.md Use `Row.Cell` to retrieve an existing cell or create a new one at a specified column within a row. ```go row := sheet.Row(1) cell := row.Cell("B") // Get/create cell B1 ``` -------------------------------- ### Create and Save a Minimal Document Source: https://github.com/esword618/unioffice/blob/main/_autodocs/configuration.md Generate a basic document with minimal configuration, add text, and save it to a file. ```go import ( "github.com/Esword618/unioffice/document" ) doc := document.New() p := doc.AddParagraph() r := p.AddRun() r.AddText("Hello, World!") doc.SaveToFile("output.docx") ``` -------------------------------- ### Set License Key Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MANIFEST.txt Demonstrates how to set the license key for UniOffice. Use SetLicenseKey for standard licensing and SetLegacyLicenseKey for older versions. ```go import ( "github.com/Esword618/unioffice/document" "github.com/Esword618/unioffice/errors" ) func main() { // Set license key err := document.SetLicenseKey("YOUR_LICENSE_KEY") if err != nil { panic(err) } // Or set legacy license key err = document.SetLegacyLicenseKey("YOUR_LEGACY_LICENSE_KEY") if err != nil { panic(err) } } ``` -------------------------------- ### Row.Cell Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet-cell-row.md Gets or creates a cell at a specific column within a row. If the cell does not exist, it will be created. ```APIDOC ## Row.Cell ### Description Gets or creates a cell at a specific column. This method is useful for accessing or initializing a cell for further manipulation. ### Method ```go func (r Row) Cell(col string) Cell ``` ### Parameters #### Path Parameters - **col** (string) - Required - Column letter (e.g., "A", "B", "AA") ### Returns - **Cell** - The cell at the given column ### Example ```go row := sheet.Row(1) cell := row.Cell("B") // Get/create cell B1 ``` ``` -------------------------------- ### Get Cell Reference Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet-cell-row.md Retrieves the cell reference string (e.g., "A1"). ```Go cell := sheet.Cell("A1") ref := cell.Reference() // "A1" ``` -------------------------------- ### Create and Save a Spreadsheet Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MANIFEST.txt Illustrates creating a new Excel workbook, adding a sheet, setting a cell value, and saving the workbook. ```go import ( "os" "github.com/Esword618/unioffice/spreadsheet" ) func main() { wb := spreadsheet.New() sheet := wb.AddSheet("Sheet1") sheet.Cell("A1").SetString("Hello, Spreadsheet!") file, err := os.Create("spreadsheet.xlsx") if err != nil { panic(err) } wb.Save(file) file.Close() } ``` -------------------------------- ### Create an Excel Spreadsheet Source: https://github.com/esword618/unioffice/blob/main/_autodocs/README.md This snippet demonstrates creating a new Excel workbook, adding a sheet, setting cell values (string and number), and saving the workbook. Requires importing the 'spreadsheet' package. ```Go import "github.com/Esword618/unioffice/spreadsheet" wb := spreadsheet.New() sheet := wb.AddSheet() sheet.Cell("A1").SetString("Name") sheet.Cell("B1").SetString("Age") sheet.Cell("A2").SetString("John") sheet.Cell("B2").SetNumber(30) wb.SaveToFile("output.xlsx") ``` -------------------------------- ### Get All Document Endnotes Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document.md Retrieves all endnotes present in the document. Returns a slice of Endnote objects. ```go func (d *Document) Endnotes() []Endnote ``` -------------------------------- ### Get or Create Cell by Reference Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet.md Retrieves a specific cell using its reference (e.g., "A1"). If the cell does not exist, it will be created. This is a fundamental operation for cell manipulation. ```go cell := sheet.Cell("A1") cell.SetString("Value") ``` -------------------------------- ### Create and Save a Presentation Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MANIFEST.txt Illustrates creating a new PowerPoint presentation, adding a slide, and saving the presentation. ```go import ( "os" "github.com/Esword618/unioffice/presentation" ) func main() { pres := presentation.New() slide := pres.AddSlide() file, err := os.Create("presentation.pptx") if err != nil { panic(err) } pres.Save(file) file.Close() } ``` -------------------------------- ### Get All Document Footnotes Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document.md Retrieves all footnotes present in the document. Returns a slice of Footnote objects. ```go func (d *Document) Footnotes() []Footnote ``` -------------------------------- ### Get Underlying XML Run Structure Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Retrieve the raw XML representation of a run. This is typically used for advanced manipulation or inspection of the document's structure. ```go r.X() ``` -------------------------------- ### Save Presentation as Template to File Path Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Saves the presentation as a template directly to a file path. Handles file creation and writing. ```go func (p *Presentation) SaveToFileAsTemplate(path string) error ``` -------------------------------- ### Create a New PowerPoint Presentation Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MODULE-STRUCTURE.md Initializes a new PowerPoint presentation object using the presentation package. ```go pres := presentation.New() ``` -------------------------------- ### Create a New Word Document Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MODULE-STRUCTURE.md Initializes a new Word document object using the document package. ```go doc := document.New() ``` -------------------------------- ### Get Underlying XML Cell Structure Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet-cell-row.md Returns the raw OOXML structure of the cell for advanced manipulation. ```Go xmlCell := cell.X() ``` -------------------------------- ### Define and Use Colors in Documents Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MODULE-STRUCTURE.md Demonstrates how to set colors for document elements using predefined colors or custom RGB values. Requires the 'color' package. ```Go import "github.com/Esword618/unioffice/color" run.Properties().SetColor(color.Red) run.Properties().SetColor(color.RGB(255, 128, 0)) ``` -------------------------------- ### Create and Save a Word Document Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MANIFEST.txt Shows how to create a new Word document, add a paragraph, and save it to a file. ```go import ( "os" "github.com/Esword618/unioffice/document" ) func main() { doc := document.New() doc.AddParagraph("Hello, UniOffice!") file, err := os.Create("document.docx") if err != nil { panic(err) } doc.Save(file) file.Close() } ``` -------------------------------- ### Create Formatted Tables in Document Source: https://github.com/esword618/unioffice/blob/main/_autodocs/README.md Shows how to add a table to a document, including rows, cells, paragraphs, and runs with text. ```go table := doc.AddTable() row := table.AddRow() cell := row.AddCell() para := cell.AddParagraph() run := para.AddRun() run.AddText("Cell Content") ``` -------------------------------- ### Save Presentation as Template to io.Writer Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Saves the presentation as a PowerPoint template (.potx) to an io.Writer. Ensure the writer is properly created and closed. ```go func (p *Presentation) SaveAsTemplate(w io.Writer) error ``` -------------------------------- ### Create a PowerPoint Presentation Source: https://github.com/esword618/unioffice/blob/main/_autodocs/README.md Use this snippet to create a new PowerPoint presentation and add a slide. The presentation is then saved to a file. Requires importing the 'presentation' package. ```Go import "github.com/Esword618/unioffice/presentation" pres := presentation.New() slide := pres.AddSlide() pres.SaveToFile("output.pptx") ``` -------------------------------- ### Create a New Excel Workbook Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MODULE-STRUCTURE.md Initializes a new Excel workbook object using the spreadsheet package. ```go wb := spreadsheet.New() ``` -------------------------------- ### Get All Defined Names Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet.md Retrieves a slice containing all defined names (named ranges) currently present in the workbook. ```go func (wb *Workbook) DefinedNames() []DefinedName ``` -------------------------------- ### Handle ErrorNotFound in UniOffice Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MANIFEST.txt Demonstrates how to check for and handle the specific ErrorNotFound error, which can occur in various operations. ```go import ( "fmt" "github.com/Esword618/unioffice/errors" ) func someOperation() error { // Simulate an operation that might fail with ErrorNotFound return errors.ErrorNotFound } func main() { err := someOperation() if err == errors.ErrorNotFound { fmt.Println("Resource not found.") } else if err != nil { fmt.Printf("An unexpected error occurred: %v\n", err) } } ``` -------------------------------- ### Create a Word Document Source: https://github.com/esword618/unioffice/blob/main/_autodocs/README.md Use this snippet to create a new Word document, add a paragraph with text, and save it to a file. Requires importing the 'document' package. ```Go import "github.com/Esword618/unioffice/document" doc := document.New() para := doc.AddParagraph() run := para.AddRun() run.AddText("Hello, World!") doc.SaveToFile("output.docx") ``` -------------------------------- ### Configure Document Section Properties Source: https://github.com/esword618/unioffice/blob/main/_autodocs/configuration.md Set page size and margins for a document's body section using the builder pattern and measurement units. ```go doc := document.New() doc.CoreProperties.SetTitle("My Title") section := doc.BodySection() section.SetPageSize(8.5*measurement.Inch, 11*measurement.Inch) section.SetPageMargins(1*measurement.Inch, 1*measurement.Inch, 1*measurement.Inch, 1*measurement.Inch) ``` -------------------------------- ### Get All Slide Masters Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Retrieve all slide masters present in the presentation by calling `pres.SlideMasters()`. This returns a slice of `SlideMaster` objects. ```Go func (p *Presentation) SlideMasters() []SlideMaster ``` -------------------------------- ### Import Common Unioffice Packages Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MODULE-STRUCTURE.md Imports essential packages for common features across document types, including common utilities, measurements, and color definitions. ```Go import "github.com/Esword618/unioffice/common" import "github.com/Esword618/unioffice/measurement" import "github.com/Esword618/unioffice/color" ``` -------------------------------- ### Save Presentation to io.Writer Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Saves the presentation to an io.Writer in ZIP format (.pptx). Ensure the writer is properly created and closed. ```go file, err := os.Create("presentation.pptx") if err != nil { panic(err) } deferr file.Close() if err := pres.Save(file); err != nil { panic(err) } ``` -------------------------------- ### Get Paragraph Style Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Retrieves the style name applied to a paragraph. Returns an empty string if no style is explicitly set. ```Go style := para.Style() // "Heading1", "Normal", etc. ``` -------------------------------- ### Add and Configure a Paragraph Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document.md Use `doc.AddParagraph()` to add a new paragraph. You can then set its style and add text content via runs. ```Go para := doc.AddParagraph() para.SetStyle("Heading1") run := para.AddRun() run.AddText("Chapter 1") ``` -------------------------------- ### Get Row Height Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet-cell-row.md Use `Row.GetHeight` to retrieve the current height of a row. It returns the default height if no specific height has been set. ```go height := row.GetHeight() ``` -------------------------------- ### Set Formulas in Spreadsheet Cells Source: https://github.com/esword618/unioffice/blob/main/_autodocs/README.md Illustrates setting raw, array, and shared formulas for spreadsheet cells. ```go cell.SetFormulaRaw("=SUM(A1:A10)") cell.SetFormulaArray("=TRANSPOSE(A1:C3)") cell.SetFormulaShared("=A1*2", 10, 0) // 10 rows ``` -------------------------------- ### Get Cell Value as Number Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet-cell-row.md Use GetValueAsNumber to retrieve the cell's value as a float64. An error is returned if the cell is not numeric. ```go value, err := cell.GetValueAsNumber() if err != nil { log.Printf("Cell is not numeric: %v", err) } ``` -------------------------------- ### Save Presentation to File Path Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Convenience method to save the presentation directly to a file path. Handles file creation and writing. ```go if err := pres.SaveToFile("output.pptx"); err != nil { log.Fatal(err) } ``` -------------------------------- ### Set Core Document Properties Source: https://github.com/esword618/unioffice/blob/main/_autodocs/configuration.md Configure standard document metadata like author, title, subject, and description using the CoreProperties API. ```go doc := document.New() doc.CoreProperties.SetAuthor("John Doe") doc.CoreProperties.SetTitle("My Document") doc.CoreProperties.SetSubject("Document Subject") doc.CoreProperties.SetDescription("This is my document") ``` -------------------------------- ### Safely Get Spreadsheet Sheet Source: https://github.com/esword618/unioffice/blob/main/_autodocs/errors.md Retrieves a sheet from a workbook, returning a specific error if the sheet is not found or a general error for other issues. ```go func getSheet(wb *spreadsheet.Workbook, name string) (*spreadsheet.Sheet, error) { sheet, err := wb.GetSheet(name) if err != nil { if err == spreadsheet.ErrorNotFound { return nil, fmt.Errorf("sheet '%s' not found", name) } return nil, err } return &sheet, nil } ``` -------------------------------- ### RunProperties.SetHighlight Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Sets the text highlighting color. Accepts a string representing the highlight color. ```APIDOC ## RunProperties.SetHighlight ### Description Sets text highlighting color. ### Method (Method signature implies a receiver method, not a direct HTTP call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **color** (string) - Required - Highlight color (yellow, green, cyan, magenta, etc.) ### Request Example ```go run.Properties().SetHighlight("yellow") ``` ``` -------------------------------- ### Set Commercial License Key Source: https://github.com/esword618/unioffice/blob/main/_autodocs/configuration.md Use this function to apply a commercial license key. Ensure the provided content and customer name match your license details. This is required to remove watermarks and enable certain features. ```go import "github.com/Esword618/unioffice/common/license" err := license.SetLicenseKey(licenseContent, "Company Name") if err != nil { log.Fatalf("Failed to set license: %v", err) } ``` -------------------------------- ### Iterate Through Cells with Values Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet-cell-row.md Use `Row.Cells` to get a slice of all cells in a row that currently contain data. This is useful for processing only populated cells. ```go for _, cell := range row.Cells() { fmt.Println(cell.GetString()) } ``` -------------------------------- ### Set Application-Specific Properties Source: https://github.com/esword618/unioffice/blob/main/_autodocs/configuration.md Configure application-specific properties for a workbook, such as application name, page count, and word count. ```go wb := spreadsheet.New() wb.AppProperties.SetApplication("MyApp") wb.AppProperties.SetPages(5) wb.AppProperties.SetWords(2500) ``` -------------------------------- ### Get Cell Value as Boolean Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet-cell-row.md Use GetValueAsBool to retrieve the cell's value as a boolean. An error is returned if the cell is not a boolean type. ```go value, err := cell.GetValueAsBool() ``` -------------------------------- ### Get Maximum Column Index Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet.md Returns the index of the highest column that contains data in the sheet. This helps in understanding the horizontal extent of the data. ```go func (s Sheet) MaxColumnIdx() uint32 { // ... implementation details ... } ``` -------------------------------- ### Presentation.SaveToFileAsTemplate Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Saves the presentation as a template file (.potx) directly to a specified file path. This method simplifies template creation. ```APIDOC ## Presentation.SaveToFileAsTemplate ### Description Saves the presentation as a template directly to a file path. ### Method func (p *Presentation) SaveToFileAsTemplate(path string) error ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **path** (string) - Required - File system path where the template will be saved ### Returns - `error` — Non-nil if the file cannot be created or written ``` -------------------------------- ### Get a Slide Layout by Name Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Use `pres.GetLayoutByName()` to retrieve a specific slide layout by its name. This method returns an error if the layout is not found. ```Go layout, err := pres.GetLayoutByName("Title Slide") if err != nil { log.Fatal(err) } ``` -------------------------------- ### Set Document Background Color Source: https://github.com/esword618/unioffice/blob/main/README.md Demonstrates how to set a document's background color by accessing and manipulating the raw CT_Background element when a direct API is not available. ```go dox := document.New() doc.X().Background = wordprocessingml.NewCT_Background() doc.X().Background.ColorAttr = &wordprocessingml.ST_HexColor{} doc.X().Background.ColorAttr.ST_HexColorRGB = color.RGB(50, 50, 50).AsRGBString() ``` -------------------------------- ### Set License Key for Commercial Licensing Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MODULE-STRUCTURE.md Set a commercial license key using the SetLicenseKey function. This is required for proprietary licensing. ```go import "github.com/Esword618/unioffice/common/license" license.SetLicenseKey(licenseContent, "Customer Name") ``` -------------------------------- ### Add Data to an Excel Sheet Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MODULE-STRUCTURE.md Demonstrates adding a string and a number to cells in an Excel sheet and saving the workbook. ```go wb := spreadsheet.New() sheet := wb.AddSheet() sheet.Cell("A1").SetString("Name") sheet.Cell("B1").SetNumber(42) wb.SaveToFile("output.xlsx") ``` -------------------------------- ### Get All Structured Document Tags Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document.md Retrieves all structured document tags (form fields) within the document. Returns a slice of StructuredDocumentTag objects. ```go func (d *Document) StructuredDocumentTags() []StructuredDocumentTag ``` -------------------------------- ### Get Cell Value as String Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet-cell-row.md Use GetString to retrieve the cell's value as a string. Returns an empty string if the cell is empty or unset. ```go value := cell.GetString() ``` -------------------------------- ### Set Paragraph Style Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Applies a predefined style to a paragraph, such as 'Heading1' or 'Normal'. Use this for consistent document structure. ```Go para.SetStyle("Heading1") para.SetStyle("Normal") ``` -------------------------------- ### Log Internal Diagnostics Source: https://github.com/esword618/unioffice/blob/main/_autodocs/errors.md Uses the unioffice.Log function for internal diagnostics and validation warnings during initialization or other operations. ```go unioffice.Log("Some message") ``` -------------------------------- ### Get Specific Document Endnote by ID Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document.md Retrieves a single endnote using its unique ID. Returns the Endnote object or an invalid endnote if not found. ```go func (d *Document) Endnote(id int64) Endnote ``` -------------------------------- ### Get Specific Document Footnote by ID Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document.md Retrieves a single footnote using its unique ID. Returns the Footnote object or an invalid footnote if not found. ```go func (d *Document) Footnote(id int64) Footnote ``` -------------------------------- ### Add and Reuse Shared Strings in Spreadsheet Source: https://github.com/esword618/unioffice/blob/main/_autodocs/README.md Demonstrates how to add a string to a spreadsheet and reuse it by its ID, or use inline strings. ```go // Add a string and get its ID id := cell1.SetString("Shared Text") // Reuse the same string with the ID cell2.SetStringByID(id) // Or use inline strings cell3.SetInlineString("Inline Text") ``` -------------------------------- ### Add Image to Presentation Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Adds an image to the presentation. Requires a common.Image object and returns a reference to the image and an error if addition fails. ```go func (p *Presentation) AddImage(i common.Image) (common.ImageRef, error) ``` -------------------------------- ### Get Raw Cell Value Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet-cell-row.md Use GetRawValue to retrieve the cell's raw value directly from the XML. An error may be returned if the value cannot be retrieved. ```go raw, err := cell.GetRawValue() ``` -------------------------------- ### Add a New Slide with Default Placeholders Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Use `pres.AddDefaultSlideWithLayout()` to add a slide with a specified layout and automatically include default placeholder content. ```Go func (p *Presentation) AddDefaultSlideWithLayout(l SlideLayout) (Slide, error) ``` -------------------------------- ### Set Cell Value in Spreadsheet Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MANIFEST.txt Shows various methods for setting cell values in a spreadsheet, including strings, numbers, booleans, and dates. ```go import ( "os" "time" "github.com/Esword618/unioffice/spreadsheet" ) func main() { wb := spreadsheet.New() sheet := wb.AddSheet("Sheet1") sheet.Cell("A1").SetString("Text Value") sheet.Cell("B1").SetNumber(123.45) sheet.Cell("C1").SetBool(true) sheet.Cell("D1").SetDate(time.Now()) file, err := os.Create("spreadsheet.xlsx") if err != nil { panic(err) } wb.Save(file) file.Close() } ``` -------------------------------- ### Get Cell Value as Time Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet-cell-row.md Use GetValueAsTime to retrieve the cell's value as a time.Time object. An error is returned if the cell does not contain a valid date. ```go date, err := cell.GetValueAsTime() ``` -------------------------------- ### Get or Create Row by Number Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet.md Retrieves a specific row using its 1-indexed number. If the row does not exist, it will be created. Useful for accessing or modifying entire rows. ```go row := sheet.Row(1) cell := row.Cell("A") cell.SetString("Header") ``` -------------------------------- ### Set Underline Style Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Apply an underline to text. Specify the underline type as a string, such as 'single' or 'double'. ```go func (r RunProperties) SetUnderline(u string) ``` -------------------------------- ### Get Workbook Date Epoch Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet.md Retrieves the epoch time used by the workbook for date calculations. This will be either January 1, 1904, or December 30, 1899. ```go func (wb *Workbook) Epoch() time.Time { // ... implementation details ... } ``` -------------------------------- ### Set Legacy License Key (Deprecated) Source: https://github.com/esword618/unioffice/blob/main/_autodocs/configuration.md Apply a legacy license code issued before June 2019. This function is for backward compatibility only and will be removed in future versions. Use `SetLicenseKey` for new licenses. ```go err := license.SetLegacyLicenseKey(legacyLicenseCode) if err != nil { log.Fatalf("Failed to set legacy license: %v", err) } ``` -------------------------------- ### Add Page Break to a Run Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Inserts a page break character, forcing all subsequent content to start on a new page. Use this to control document pagination. ```Go run.AddText("Content on page 1") run.AddPageBreak() run.AddText("Content on page 2") ``` -------------------------------- ### Access Low-Level XML Schema Types Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MODULE-STRUCTURE.md Shows how to access the low-level XML schema types of a document object for advanced manipulation. ```go doc := document.New() // Low-level XML access when needed xmlDoc := doc.X() ``` -------------------------------- ### Set Run Text Bold Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Apply or remove bold formatting for text within a run. This is a common text styling option. ```go run.Properties().SetBold(true) ``` -------------------------------- ### Run.Text Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Returns the text content of the run. ```APIDOC ## Run.Text ### Description Returns the text content of the run. ### Method func (r Run) Text() string ### Parameters None ### Returns `string` — The combined text content of the run ### Example ```go text := run.Text() ``` ``` -------------------------------- ### Get Document Body Section Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document.md Retrieves the document's main body section, which applies document-wide settings unless overridden by specific sections. Returns a Section object. ```go func (d *Document) BodySection() Section ``` ```go section := doc.BodySection() section.SetPageSize(measurement.NewSize(8.5*measurement.Inch, 11*measurement.Inch)) ``` -------------------------------- ### Set Text Highlight Color Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Apply a background highlight color to the text. Use color names like 'yellow' or 'green'. ```go func (r RunProperties) SetHighlight(color string) ``` ```go run.Properties().SetHighlight("yellow") ``` -------------------------------- ### Safely Add Image to Workbook Source: https://github.com/esword618/unioffice/blob/main/_autodocs/errors.md Loads an image from a given path and adds it to the workbook, returning specific errors for image loading or addition failures. ```go func addImage(wb *spreadsheet.Workbook, imgPath string) (*common.ImageRef, error) { img, err := common.LoadImage(imgPath) if err != nil { return nil, fmt.Errorf("failed to load image: %w", err) } imgRef, err := wb.AddImage(img) if err != nil { return nil, fmt.Errorf("failed to add image to workbook: %w", err) } return &imgRef, nil } ``` -------------------------------- ### Set Font Size Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Configure the font size for text. The size is specified in half-points, where 24 represents 12-point font. ```go func (r RunProperties) SetSize(size int) ``` ```go run.Properties().SetSize(24) // 12 point font run.Properties().SetSize(48) // 24 point font ``` -------------------------------- ### Save Document to File Path Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document.md Use `doc.SaveToFile()` for a convenient way to save the document directly to a specified file path. Handles file creation and writing. ```Go if err := doc.SaveToFile("output.docx"); err != nil { log.Fatal(err) } ``` -------------------------------- ### Iterate Through Presentation Slides Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Retrieve all slides in the presentation using `pres.Slides()` and iterate over the returned slice to process each slide. ```Go for _, slide := range pres.Slides() { // Process each slide } ``` -------------------------------- ### Insert Table After Paragraph Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document.md Use `doc.InsertTableAfter()` to insert a new table immediately following a specified paragraph. ```Go table := d.InsertTableAfter(relativeTo Paragraph) Table ``` -------------------------------- ### Run.X Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Retrieves the underlying XML representation of the run. ```APIDOC ## Run.X ### Description Returns the underlying XML representation. ### Method `Run.X()` ### Parameters None ### Returns `*wml.CT_R` — The underlying OOXML run structure ``` -------------------------------- ### Presentation.Save Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Saves the presentation to an io.Writer in ZIP format (.pptx). This method is useful for writing the presentation data to memory buffers or network streams. ```APIDOC ## Presentation.Save ### Description Writes the presentation to an io.Writer in ZIP format (.pptx). ### Method func (p *Presentation) Save(w io.Writer) error ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **w** (io.Writer) - Required - The writer to save the presentation to ### Returns - `error` — Non-nil if save fails ### Example ```go file, err := os.Create("presentation.pptx") if err != nil { panic(err) } deffer file.Close() if err := pres.Save(file); err != nil { panic(err) } ``` ``` -------------------------------- ### Presentation.SaveAsTemplate Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Saves the presentation as a PowerPoint template (.potx) to an io.Writer. This is useful for creating reusable template files. ```APIDOC ## Presentation.SaveAsTemplate ### Description Saves the presentation as a PowerPoint template (.potx). ### Method func (p *Presentation) SaveAsTemplate(w io.Writer) error ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **w** (io.Writer) - Required - The writer to save the template to ### Returns - `error` — Non-nil if save fails ``` -------------------------------- ### Color RGB Constructor Source: https://github.com/esword618/unioffice/blob/main/_autodocs/types.md Represents an RGB color. Use the color.RGB function to create a new color instance with specified red, green, and blue values. ```go c := color.RGB(255, 0, 0) // Red color ``` -------------------------------- ### Insert Table Before Paragraph Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document.md Use `doc.InsertTableBefore()` to insert a new table immediately preceding a specified paragraph. ```Go table := d.InsertTableBefore(relativeTo Paragraph) Table ``` -------------------------------- ### Run Methods Source: https://github.com/esword618/unioffice/blob/main/_autodocs/types.md Methods available for the Run type, which represents a run of text with consistent formatting. ```APIDOC ## Run ### Description Represents a run of text with consistent formatting within a paragraph. ### Methods - **X()** (*wml.CT_R): Returns underlying XML type. - **AddText**(s string): Adds text to the run. - **AddBreak**(): Adds a line break. - **AddImage**(img common.Image, w, h measurement.Distance) Error: Adds an inline image. - **Properties**(): RunProperties: Returns run formatting properties. ``` -------------------------------- ### Define Measurement Units Source: https://github.com/esword618/unioffice/blob/main/_autodocs/configuration.md Utilize the measurement package to define dimensions like width, height, and margins using various units such as inches. ```go import "github.com/Esword618/unioffice/measurement" width := 8.5 * measurement.Inch height := 11 * measurement.Inch margin := 1 * measurement.Inch ``` -------------------------------- ### Set Paragraph Spacing Before Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Control the vertical space that appears before a paragraph. Use measurement.Distance for precise control. ```go props := para.Properties() props.SetSpacingBefore(spacing measurement.Distance) ``` -------------------------------- ### Run.AddText Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/document-text-formatting.md Adds text to the run. ```APIDOC ## Run.AddText ### Description Adds text to the run. ### Method func (r Run) AddText(s string) ### Parameters #### Path Parameters - **s** (string) - Required - The text to add ### Returns None ### Example ```go run := para.AddRun() run.AddText("Hello, World!") ``` ``` -------------------------------- ### Safe Document Save Pattern Source: https://github.com/esword618/unioffice/blob/main/_autodocs/errors.md A robust pattern for saving documents that first validates the document structure and then handles potential save errors. It wraps errors for better context. ```go func saveDocument(doc *document.Document, filePath string) error { // Validate before saving if err := doc.Validate(); err != nil { return fmt.Errorf("validation failed: %w", err) } // Save to file if err := doc.SaveToFile(filePath); err != nil { return fmt.Errorf("save failed: %w", err) } return nil } ``` -------------------------------- ### Save Workbook to File Path Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet.md Convenience method to save the workbook directly to a specified file path. Handles file creation and writing. ```go if err := wb.SaveToFile("output.xlsx"); err != nil { log.Fatal(err) } ``` -------------------------------- ### Add Text to a Word Document Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MODULE-STRUCTURE.md Demonstrates adding a paragraph with text to a Word document and saving it. ```go doc := document.New() para := doc.AddParagraph() run := para.AddRun() run.AddText("Hello, World!") doc.SaveToFile("output.docx") ``` -------------------------------- ### Add a Slide to a PowerPoint Presentation Source: https://github.com/esword618/unioffice/blob/main/_autodocs/MODULE-STRUCTURE.md Demonstrates adding a new slide to a PowerPoint presentation and saving it. ```go pres := presentation.New() slide := pres.AddSlide() pres.SaveToFile("output.pptx") ``` -------------------------------- ### GetLicenseKey Source: https://github.com/esword618/unioffice/blob/main/_autodocs/configuration.md Retrieves the current license key configuration. This function returns a copy of the active license key or a default unlicensed key if no license is set. ```APIDOC ## GetLicenseKey ### Description Retrieves the current license key configuration. This function returns a copy of the active license key or a default unlicensed key if no license is set. ### Method ```go func GetLicenseKey() *LicenseKey ``` ### Parameters None ### Returns - **LicenseKey** - A copy of the current license key, or a default unlicensed key if none is set ### Request Example ```go lk := license.GetLicenseKey() fmt.Println(lk.TypeToString()) fmt.Println("Licensed:", lk.IsLicensed()) ``` ``` -------------------------------- ### Presentation.SaveToFile Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md A convenience method to save the presentation directly to a specified file path. It handles file creation and writing. ```APIDOC ## Presentation.SaveToFile ### Description Convenience method to save the presentation directly to a file path. ### Method func (p *Presentation) SaveToFile(path string) error ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **path** (string) - Required - File system path where the presentation will be saved ### Returns - `error` — Non-nil if the file cannot be created or written ### Example ```go if err := pres.SaveToFile("output.pptx"); err != nil { log.Fatal(err) } ``` ``` -------------------------------- ### PlaceHolder Methods Source: https://github.com/esword618/unioffice/blob/main/_autodocs/types.md Methods for interacting with placeholder shapes on a slide. ```APIDOC ## PlaceHolder Represents a placeholder shape within a slide. ### Methods - **Name()**: Returns the placeholder name. - **Type()**: Returns the placeholder type. ``` -------------------------------- ### Add and Set Cell in a Row Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/spreadsheet-cell-row.md Use AddCell to add a new cell to a row and then set its value using methods like SetString. ```go row := sheet.AddRow() cell1 := row.AddCell() cell1.SetString("Name") cell2 := row.AddCell() cell2.SetString("Age") ``` -------------------------------- ### Handle File I/O Errors Source: https://github.com/esword618/unioffice/blob/main/_autodocs/errors.md Logs a fatal error if saving a document to a file fails. This covers issues like file creation or write errors. ```go if err := doc.SaveToFile("output.docx"); err != nil { log.Fatalf("Failed to save document: %v", err) } ``` -------------------------------- ### Presentation.AddDefaultSlideWithLayout Source: https://github.com/esword618/unioffice/blob/main/_autodocs/api-reference/presentation.md Adds a new slide using a specified layout and populates it with default placeholder content. ```APIDOC ## Presentation.AddDefaultSlideWithLayout Adds a new slide with a layout using default placeholder content. ### Description This method creates a new slide based on the provided `SlideLayout` and automatically populates its standard placeholders (like title and body text) with default content, simplifying the initial setup of slides. ### Method `AddDefaultSlideWithLayout(l SlideLayout) (Slide, error)` ### Parameters #### Path Parameters - **l** (SlideLayout) - Required - The slide layout to use for the new slide. ### Returns - `Slide` — A new slide object with the specified layout and default placeholders. - `error` — An error if the layout is invalid or cannot be applied. ### Source `presentation/presentation.go` ```