### Install Gooxml Library Source: https://github.com/carmel/gooxml/blob/master/_autodocs/README.md Use this command to install the gooxml library using go get. ```bash go get github.com/carmel/gooxml/ ``` -------------------------------- ### Configure Spreadsheet Page Setup Source: https://github.com/carmel/gooxml/blob/master/_autodocs/configuration.md Set print margins and paper size for a spreadsheet sheet. Margins are specified in inches. ```go sheet := wb.AddSheet() // Set print margins in inches sheet.SetPageMargins(0.75, 0.75, 1.0, 1.0) // Left, right, top, bottom // Set paper size (letter, legal, etc.) // This is set via print settings ``` -------------------------------- ### Configure Document Page Setup Source: https://github.com/carmel/gooxml/blob/master/_autodocs/configuration.md Set page margins, orientation (portrait/landscape), and paper size for a document. Margins and paper size are specified in inches. ```go doc := document.New() section := doc.BodySection() // Set page margins in inches section.SetPageMargins(1.0, 1.0, 1.0, 1.0) // Set page orientation section.SetPortrait() // Default section.SetLandscape() // Set paper size section.SetPageSize(8.5, 11.0) // Letter size in inches ``` -------------------------------- ### Set Font Size Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Sets the font size in half-points. For example, 24 half-points corresponds to 12pt. ```go props := run.Properties() props.SetFontSize(24) // 12pt font props.SetFontSize(48) // 24pt font ``` -------------------------------- ### Run.String Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Returns the text content of the run as a plain string. This is a convenient way to get the combined text of a run. ```APIDOC ## Run.String ### Description Returns the text content of the run as a plain string. This is a convenient way to get the combined text of a run. ### Method `func (r Run) String() string` ### Returns - `string` — The text content ### Example ```go run := para.AddRun() run.AddText("Sample") text := run.String() // "Sample" ``` ``` -------------------------------- ### Retrieve All Sheets Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-workbook.md Gets all sheets present in the workbook. This allows iteration over each sheet to process its rows. ```go wb := spreadsheet.New() sheets := wb.Sheets() for _, sheet := range sheets { for _, row := range sheet.Rows() { // Process row } } ``` -------------------------------- ### Get Raw Slide XML Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Retrieves the underlying raw Office Open XML structure of a slide. ```go slide := pres.AddSlide() rawXML := slide.X() ``` -------------------------------- ### Get Raw Workbook XML Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-workbook.md Retrieve the underlying raw XML structure of the workbook for direct manipulation. ```go wb := spreadsheet.New() rawWorkbook := wb.X() ``` -------------------------------- ### Convert Measurement Units Source: https://github.com/carmel/gooxml/blob/master/_autodocs/00-START-HERE.md Provides examples of converting common measurement units like inches, centimeters, and points for use in presentations and documents. ```go // Available in presentations and documents presentation.Inch(1) // 1 inch presentation.Cm(2.54) // 2.54 cm (= 1 inch) presentation.Point(72) // 72 points (= 1 inch) ``` -------------------------------- ### Define Measurement Units in Presentation Source: https://github.com/carmel/gooxml/blob/master/_autodocs/configuration.md Provides examples of using different measurement unit functions like Inch, Cm, Point, and Emu for positioning and sizing in presentations. ```go // 1 inch distance := presentation.Inch(1) // 2.54 centimeters (equivalent to 1 inch) distance := presentation.Cm(2.54) // 72 points (1 inch at 72 DPI) distance := presentation.Point(72) // 914400 EMU (1 inch) distance := presentation.Emu(914400) ``` -------------------------------- ### Get Image Format Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/common-and-utilities.md The `Format()` method returns the image's format identifier as a string (e.g., "png"). This is useful for verifying or using the image format. ```go img := common.ImageFromFile("photo.png") fmt.Println(img.Format()) // "png" ``` -------------------------------- ### Set Table Width Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-table.md Use this method to set the table width in inches. Call `table.Properties()` to get the table properties object. ```Go props := table.Properties() props.SetWidth(6.0) ``` -------------------------------- ### Enable Table Borders Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-table.md Use this method to enable or disable borders on a table. Call `table.Properties()` to get the table properties object. ```Go props := table.Properties() props.SetBorders(true) ``` -------------------------------- ### Get Raw XML Structure Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Retrieves the underlying raw XML structure of the presentation. Use this for advanced manipulation or inspection of the presentation's XML. ```go pres := presentation.New() rawXML := pres.X() ``` -------------------------------- ### Get All Paragraphs Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-document.md Retrieves a slice containing all paragraphs present in the document's body, in their original order. Each paragraph can be processed individually. ```go paragraphs := doc.Paragraphs() for _, para := range paragraphs { fmt.Println(para.String()) } ``` -------------------------------- ### Get and Set Column Width Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-features.md Retrieves a column by its index and sets its width in character units. Column index 1 corresponds to column A. Use this to adjust column visibility. ```go sheet := wb.AddSheet() col := sheet.Column(1) // Column A col.SetWidth(20) ``` ```go col := sheet.Column(1) col.SetWidth(15) ``` -------------------------------- ### Create and Save an Excel Spreadsheet Source: https://github.com/carmel/gooxml/blob/master/_autodocs/README.md Demonstrates how to create a new Excel workbook, add a sheet, populate cells with data and formatting, add a formula, and save the workbook. ```go package main import ( "github.com/carmel/gooxml/spreadsheet" ) func main() { // Create new workbook wb := spreadsheet.New() sheet := wb.AddSheet() sheet.SetName("Data") // Add data with formatting sheet.Cell("A1").SetString("Product") sheet.Cell("B1").SetString("Sales") sheet.Cell("A2").SetString("Widget") sheet.Cell("B2").SetNumber(1000) // Style cells style := sheet.Cell("A1").Style() style.SetBold(true) style.SetBackgroundColor("D3D3D3") // Add formula sheet.Cell("B3").SetFormula("SUM(B2:B2)") // Save to file wb.SaveToFile("spreadsheet.xlsx") } ``` -------------------------------- ### Get Slide Count Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Returns the total number of slides present in the presentation as an integer. ```APIDOC ## `func (p *Presentation) SlideCount() int` ### Description Returns the total number of slides. ### Returns - `int` — Number of slides ``` -------------------------------- ### Create a New Document Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-document.md Initializes a new, empty Word document with default settings. The document is ready to have content added and can be saved to a file. ```go package main import ( "os" "github.com/carmel/gooxml/document" ) func main() { doc := document.New() // Document is ready for content doc.SaveToFile("output.docx") } ``` -------------------------------- ### Get All Tables Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-document.md Retrieves all tables present in the document, including any tables nested within cells. ```APIDOC ## Get All Tables ### Description Retrieves all tables present in the document, including any tables nested within cells. ### Method `func (d *Document) Tables() []Table` ### Returns - `[]Table` — Slice of all tables in the document ### Example ```go tables := doc.Tables() for _, table := range tables { rows := table.Rows() fmt.Printf("Table with %d rows\n", len(rows)) } ``` ``` -------------------------------- ### Freeze Panes in Gooxml Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-features.md Illustrates how to freeze rows and/or columns in a spreadsheet to keep them visible during scrolling. The parameters specify the number of rows and columns to freeze starting from the top-left. ```go sheet := wb.AddSheet() // Freeze first row only sheet.FreezePanes(1, 0) // Freeze first 3 rows and 2 columns sheet.FreezePanes(3, 2) // Freeze first column only sheet.FreezePanes(0, 1) ``` -------------------------------- ### Create an Excel Spreadsheet Source: https://github.com/carmel/gooxml/blob/master/_autodocs/00-START-HERE.md Quickly create a new Excel spreadsheet, add a sheet, set cell values as strings and numbers, and save it to a file. ```go wb := spreadsheet.New() sheet := wb.AddSheet() sheet.Cell("A1").SetString("Name") sheet.Cell("B1").SetString("Value") sheet.Cell("A2").SetString("Data") sheet.Cell("B2").SetNumber(42) wb.SaveToFile("output.xlsx") ``` -------------------------------- ### Get All Paragraphs Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-document.md Retrieves all paragraphs present in the document's body, maintaining their original order. ```APIDOC ## Get All Paragraphs ### Description Retrieves all paragraphs present in the document's body, maintaining their original order. ### Method `func (d *Document) Paragraphs() []Paragraph` ### Returns - `[]Paragraph` — Slice of all paragraphs in document body ### Example ```go paragraphs := doc.Paragraphs() for _, para := range paragraphs { fmt.Println(para.String()) } ``` ``` -------------------------------- ### Get Raw XML for a Run Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Retrieves the underlying raw XML structure of a run. This is useful for advanced manipulation or inspection of the run's XML representation. ```go run := para.AddRun() rawXML := run.X() ``` -------------------------------- ### Apply Document Styles Source: https://github.com/carmel/gooxml/blob/master/_autodocs/configuration.md Demonstrates how to access and apply predefined styles like 'Heading1' and 'Normal' to document paragraphs. Also shows how to set paragraph indentation. ```go doc := document.New() // Access existing style styles := doc.Styles // Apply style to paragraph para := doc.AddParagraph() para.SetStyle("Heading1") para.AddRun().AddText("Section Heading") // Style with formatting para2 := doc.AddParagraph() para2.SetStyle("Normal") props := para2.Properties() props.SetIndentation(0.5, 0, 0) para2.AddRun().AddText("Indented text") ``` -------------------------------- ### Get All Slides Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Retrieves a slice containing all slides currently in the presentation. This is useful for iterating over and processing each slide. ```go pres := presentation.New() slides := pres.Slides() for _, slide := range slides { // Process slide } ``` -------------------------------- ### Get Image File Path Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/common-and-utilities.md The `Path()` method returns the original file path if the image was created using `ImageFromFile`. If the image was created from bytes, it returns an empty string. ```go img := common.ImageFromFile("photo.png") fmt.Println(img.Path()) // "photo.png" ``` -------------------------------- ### Get Paragraph Text Content Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Returns the concatenated text from all runs within the paragraph as a single string. ```go para := doc.AddParagraph() run := para.AddRun() run.AddText("Sample text") content := para.String() // "Sample text" ``` -------------------------------- ### Create a New Word Document Source: https://github.com/carmel/gooxml/blob/master/_autodocs/INDEX.md Demonstrates the basic steps to create a new Word document, add a paragraph with text, and save it to a file. ```go doc := document.New() para := doc.AddParagraph() run := para.AddRun() run.AddText("Hello, World!") doc.SaveToFile("output.docx") ``` -------------------------------- ### Create a Word Document Source: https://github.com/carmel/gooxml/blob/master/_autodocs/00-START-HERE.md Quickly create a new Word document, set its title, add a paragraph with text, and save it to a file. ```go doc := document.New() doc.CoreProperties.SetTitle("My Document") para := doc.AddParagraph() para.AddRun().AddText("Hello, World!") doc.SaveToFile("output.docx") ``` -------------------------------- ### Get Image Data Bytes Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/common-and-utilities.md The `Data()` method returns a pointer to the image's byte data if it was created using `ImageFromBytes`. It returns `nil` if the image was created from a file. ```go data := []byte{/* PNG data */} img := common.ImageFromBytes("png", data) imgData := img.Data() // &data ``` -------------------------------- ### Create a New Spreadsheet Source: https://github.com/carmel/gooxml/blob/master/_autodocs/INDEX.md Shows how to create a new Excel spreadsheet, add data to cells, and save the workbook. ```go wb := spreadsheet.New() sheet := wb.AddSheet() sheet.Cell("A1").SetString("Data") sheet.Cell("B1").SetNumber(42) wb.SaveToFile("output.xlsx") ``` -------------------------------- ### Run.AddPageBreak Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Adds a page break after the current run. This forces the subsequent content to start on a new page. ```APIDOC ## Run.AddPageBreak ### Description Adds a page break after the current run. This forces the subsequent content to start on a new page. ### Method `func (r Run) AddPageBreak()` ### Example ```go run := para.AddRun() run.AddText("End of page") run.AddPageBreak() ``` ``` -------------------------------- ### Create and Save a Word Document Source: https://github.com/carmel/gooxml/blob/master/_autodocs/README.md Demonstrates how to create a new Word document, add a formatted paragraph, add a table, and save the document to a file. ```go package main import ( "github.com/carmel/gooxml/document" ) func main() { // Create new document doc := document.New() // Add paragraph with formatted text para := doc.AddParagraph() run := para.AddRun() run.AddText("Hello, World!") props := run.Properties() props.SetBold(true) props.SetFontSize(24) // Add table table := doc.AddTable() row := table.AddRow() cell := row.AddCell() cell.AddParagraph().AddRun().AddText("Cell content") // Save to file doc.SaveToFile("document.docx") } ``` -------------------------------- ### Get All Slides Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Retrieves a slice containing all the `Slide` objects currently in the presentation. This allows for iteration and processing of each slide. ```APIDOC ## `func (p *Presentation) Slides() []Slide` ### Description Returns all slides in the presentation. ### Returns - `[]Slide` — Slice of all slides ``` -------------------------------- ### Create a New Presentation Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Creates a new empty presentation with default master slide and layout. This is the entry point for creating a new PowerPoint file. ```go package main import ( "github.com/carmel/gooxml/presentation" ) func main() { pres := presentation.New() slide := pres.AddSlide() title := slide.AddTitle() title.AddParagraph().AddRun().AddText("Slide Title") pres.SaveToFile("presentation.pptx") } ``` -------------------------------- ### Configure Presentation Shape Styles Source: https://github.com/carmel/gooxml/blob/master/_autodocs/configuration.md Illustrates how to set the fill color and outline properties for a shape in a presentation slide. ```go shape := slide.AddRectangle( presentation.Inch(1), presentation.Inch(1), presentation.Inch(2), presentation.Inch(2)) props := shape.Properties() props.SetFill(color.RGB(0, 128, 255)) // Blue props.SetLine(color.RGB(0, 0, 0), presentation.Point(2)) // Black outline ``` -------------------------------- ### Get Category Axis Title Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-chart.md Retrieves the title of a category axis. This is useful for inspecting axis properties after creation. ```go axis := chart.CategoryAxis() title := axis.GetTitle() ``` -------------------------------- ### Configure Document Headers and Footers Source: https://github.com/carmel/gooxml/blob/master/_autodocs/configuration.md Set up custom headers with company names and footers with page numbers for a document. Assign these to the document's default header and footer sections. ```go doc := document.New() // Add header header := doc.AddHeader() para := header.AddParagraph() para.AddRun().AddText("Company Name") // Add footer with page numbers footer := doc.AddFooter() para = footer.AddParagraph() para.AddRun().AddText("Page ") para.AddRun().AddPageNumber() // Assign to section section := doc.BodySection() section.SetDefaultHeader(header) section.SetDefaultFooter(footer) ``` -------------------------------- ### Access or Create a Cell Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-workbook.md Get or create a cell using its reference string (e.g., "A1"). The Cell method allows setting string or numeric values. It throws an error if the cell reference format is invalid. ```go sheet := wb.AddSheet() cell := sheet.Cell("A1") cell.SetString("Value") cell = sheet.Cell("C5") cell.SetNumber(42) ``` -------------------------------- ### Get All Paragraphs in a Cell Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-table.md Retrieves a slice of all paragraphs within a cell. This allows iteration and processing of cell content. ```go cell := row.Cells()[0] for _, para := range cell.Paragraphs() { // Process paragraph } ``` -------------------------------- ### Set Document Description Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/common-and-utilities.md Use `SetDescription` to provide a brief summary of the document's content. This aids in understanding the document's purpose. ```Go doc.CoreProperties.SetDescription("Annual financial report for 2024") ``` -------------------------------- ### SetFontSize Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Sets the font size for a run's text in half-points. For example, 24 half-points equals 12pt. ```APIDOC ## SetFontSize ### Description Sets the font size in half-points (1 point = 2 half-points). ### Method func (rp RunProperties) SetFontSize(sz uint32) ### Parameters #### Path Parameters - **sz** (uint32) - Required - Size in half-points ### Request Example ```go props := run.Properties() props.SetFontSize(24) // 12pt font props.SetFontSize(48) // 24pt font ``` ``` -------------------------------- ### Create a New Presentation Source: https://github.com/carmel/gooxml/blob/master/_autodocs/INDEX.md Illustrates how to create a new PowerPoint presentation, add a slide with a title, and save it. ```go pres := presentation.New() slide := pres.AddSlide() title := slide.AddTitle() title.AddParagraph().AddRun().AddText("Slide Title") pres.SaveToFile("output.pptx") ``` -------------------------------- ### Run.AddLineBreak Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Adds a line break within the run. This creates a new line without starting a new paragraph. ```APIDOC ## Run.AddLineBreak ### Description Adds a line break within the run. This creates a new line without starting a new paragraph. ### Method `func (r Run) AddLineBreak()` ### Example ```go run := para.AddRun() run.AddText("Line 1") run.AddLineBreak() run.AddText("Line 2") ``` ``` -------------------------------- ### Save Presentation to File Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Writes the presentation directly to a file at the specified path. This is the most common way to save a presentation. ```go if err := pres.SaveToFile("output.pptx"); err != nil { panic(err) } ``` -------------------------------- ### Get Slide Count Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Returns the total number of slides in the presentation. This method is useful for quickly checking the size of the presentation. ```go pres := presentation.New() pres.AddSlide() pres.AddSlide() count := pres.SlideCount() // 3 ``` -------------------------------- ### Configure Presentation Core Properties and Content Source: https://github.com/carmel/gooxml/blob/master/_autodocs/configuration.md Modify presentation metadata and add slides with titles. A default blank slide, master slide, and layout are created upon initialization. ```go pres := presentation.New() // Modify metadata pres.CoreProperties.SetTitle("Presentation Title") pres.CoreProperties.SetCreator("Author Name") // Add slides and content slide := pres.AddSlide() title := slide.AddTitle() title.AddParagraph().AddRun().AddText("Title Slide") ``` -------------------------------- ### Format Text in a Document Source: https://github.com/carmel/gooxml/blob/master/_autodocs/INDEX.md Demonstrates how to apply formatting such as bold, font size, and color to text within a document paragraph. ```go run := para.AddRun() run.AddText("Formatted") props := run.Properties() props.SetBold(true) props.SetFontSize(24) props.SetColor("FF0000") ``` -------------------------------- ### Apply Style to Cell Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-cell-and-row.md Get and modify the style of a cell to apply formatting like bold text and font color. ```go cell := sheet.Cell("A1") cell.SetString("Bold Red") style := cell.Style() style.SetBold(true) style.SetFontColor("FF0000") ``` -------------------------------- ### Create and Save Office Documents Source: https://github.com/carmel/gooxml/blob/master/_autodocs/00-START-HERE.md Demonstrates the creation and saving of Word documents, Excel spreadsheets, and PowerPoint presentations using the Gooxml library. ```go doc := document.New() doc.AddParagraph().AddRun().AddText("Hello") doc.SaveToFile("doc.docx") wb := spreadsheet.New() sheet := wb.AddSheet() sheet.Cell("A1").SetString("Data") wb.SaveToFile("sheet.xlsx") pres := presentation.New() slide := pres.AddSlide() slide.AddTitle().AddParagraph().AddRun().AddText("Title") pres.SaveToFile("pres.pptx") ``` -------------------------------- ### Get Paragraph Style Identifier Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Retrieves the style identifier applied to the paragraph. Returns an empty string if no style is set. ```go style := para.Style() if style != "" { fmt.Printf("Paragraph uses style: %s\n", style) } ``` -------------------------------- ### Open Document Safely Source: https://github.com/carmel/gooxml/blob/master/_autodocs/errors.md Use this pattern to open an existing document and handle potential errors during the opening process. Ensure the document is closed using defer. ```go doc, err := document.Open("file.docx") if err != nil { log.Fatalf("Failed to open document: %v", err) } deferrat doc.Close() // Document is now safe to use para := doc.AddParagraph() para.AddRun().AddText("Content") ``` -------------------------------- ### Get All Shapes on Slide Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Retrieves a slice containing all shapes currently present on the slide. This allows for iteration and processing of existing elements. ```go slide := pres.AddSlide() shapes := slide.Shapes() for _, shape := range shapes { // Process shape } ``` -------------------------------- ### Create and Save a PowerPoint Presentation Source: https://github.com/carmel/gooxml/blob/master/_autodocs/README.md Demonstrates how to create a new PowerPoint presentation, add a slide with a title, add a text box, add a shape with a specific color, and save the presentation. ```go package main import ( "github.com/carmel/gooxml/presentation" "github.com/carmel/gooxml/color" ) func main() { // Create new presentation pres := presentation.New() slide := pres.AddSlide() title := slide.AddTitle() title.AddParagraph().AddRun().AddText("Presentation Title") // Add text box ttextBox := slide.AddTextBox( presentation.Inch(1), presentation.Inch(2), presentation.Inch(8), presentation.Inch(3)) ttextBox.AddParagraph().AddRun().AddText("Slide content") // Add shape with color rect := slide.AddRectangle( presentation.Inch(0.5), presentation.Inch(0.5), presentation.Inch(2), presentation.Inch(2)) props := rect.Properties() props.SetFill(color.RGB(0, 128, 255)) // Save to file pres.SaveToFile("presentation.pptx") } ``` -------------------------------- ### Configure Spreadsheet Cell Styles Source: https://github.com/carmel/gooxml/blob/master/_autodocs/configuration.md Shows how to set various style properties for a spreadsheet cell, including bold text, font size, background color, alignment, and number format. ```go cell := sheet.Cell("A1") cell.SetString("Sales") style := cell.Style() style.SetBold(true) style.SetFontSize(12) style.SetBackgroundColor("D3D3D3") // Light gray style.SetHorizontalAlignment("center") style.SetNumberFormat("$#,##0.00") ``` -------------------------------- ### Get Raw XML Structure of a Paragraph Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Use this method to access the underlying raw XML structure of a paragraph for direct manipulation. ```go para := doc.AddParagraph() rawXML := para.X() ``` -------------------------------- ### New Workbook Constructor Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-workbook.md Creates a new, empty spreadsheet workbook with default styling and a single blank sheet. This is the entry point for creating new Excel files. ```APIDOC ## New Workbook Constructor ### Description Creates a new, empty spreadsheet workbook with default styling and a single blank sheet. This is the entry point for creating new Excel files. ### Function Signature `func New() *Workbook` ### Returns - `*Workbook` — A pointer to a newly initialized workbook with default content types and relationships. ``` -------------------------------- ### Get Raw Chart XML Structure Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-chart.md Retrieves the underlying raw XML structure of the chart. This is useful for advanced customization or inspection. ```go chart := sheet.AddBarChart() rawXML := chart.X() ``` -------------------------------- ### New Presentation Constructor Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Creates a new, empty Presentation object with default master slide and layout. This is the entry point for creating a new PowerPoint file. ```APIDOC ## `func New() *Presentation` ### Description Creates a new empty presentation with default master slide and layout. ### Returns - `*Presentation` — A newly initialized presentation with one blank slide ``` -------------------------------- ### Set Row Height Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-table.md Use this method to set the row height in inches. Call `row.Properties()` to get the row properties object. ```Go props := row.Properties() props.SetHeight(0.5) ``` -------------------------------- ### Set Cell Width Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-table.md Use this method to set the cell width in inches. Call `cell.Properties()` to get the cell properties object. ```Go props := cell.Properties() props.SetWidth(2.0) ``` -------------------------------- ### Format Text in a Document Run Source: https://github.com/carmel/gooxml/blob/master/_autodocs/00-START-HERE.md Illustrates how to apply formatting such as bold and color to a text run within a document paragraph. ```go run := para.AddRun() props := run.Properties() props.SetBold(true) props.SetColor("FF0000") ``` -------------------------------- ### Define RGB Colors Source: https://github.com/carmel/gooxml/blob/master/_autodocs/00-START-HERE.md Shows how to define colors using their Red, Green, and Blue (RGB) values. ```go color.RGB(255, 0, 0) // Red color.RGB(0, 255, 0) // Green color.RGB(0, 0, 255) // Blue ``` -------------------------------- ### Set Document Keywords Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/common-and-utilities.md Use `SetKeywords` to add keywords for document searching. Keywords should be comma-separated. ```Go doc.CoreProperties.SetKeywords("financial, report, 2024") ``` -------------------------------- ### Get All Nested Tables in a Cell Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-table.md Retrieves a slice of all tables nested within a cell. Useful for navigating complex document structures. ```go cell := row.Cells()[0] for _, table := range cell.Tables() { // Process nested table } ``` -------------------------------- ### Create and Save a New Workbook Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-workbook.md Creates a new workbook, adds a sheet with a cell containing text, and saves it to a file. Requires the spreadsheet package. ```go package main import ( "github.com/carmel/gooxml/spreadsheet" ) func main() { wb := spreadsheet.New() sheet := wb.AddSheet() row := sheet.AddRow() cell := row.AddCell() cell.SetString("Hello, World!") wb.SaveToFile("output.xlsx") } ``` -------------------------------- ### Get Raw XML for a Cell Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-table.md Retrieves the underlying raw XML structure of a Cell object. Useful for direct XML manipulation. ```go cell := row.AddCell() rawXML := cell.X() ``` -------------------------------- ### Opening Documents with Error Handling Source: https://github.com/carmel/gooxml/blob/master/_autodocs/errors.md Shows how to handle potential errors when opening .docx files using document.Open() and document.OpenTemplate(). Common errors include file not found, permission issues, or invalid file formats. ```Go // Opening documents doc, err := document.Open("template.docx") if err != nil { // Handle: file not found, permission denied, invalid format } doc, err := document.OpenTemplate("template.docx") if err != nil { // Handle: file not found, permission denied, invalid format } ``` -------------------------------- ### Open an Existing Document Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-document.md Loads an existing Word document from the specified file path. Ensure the file exists and is a valid .docx file. The document should be closed after use. ```go doc, err := document.Open("template.docx") if err != nil { panic(err) } deffer doc.Close() ``` -------------------------------- ### Get All Cells in a Row Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-table.md Retrieves a slice of all cells contained within a specific row. This is useful for iterating over or modifying existing cells. ```go row := table.Rows()[0] for _, cell := range row.Cells() { // Process cell } ``` -------------------------------- ### Format Spreadsheet Cell Style Source: https://github.com/carmel/gooxml/blob/master/_autodocs/00-START-HERE.md Demonstrates how to set formatting properties like bold and background color for a specific spreadsheet cell. ```go cell := sheet.Cell("A1") style := cell.Style() style.SetBold(true) style.SetBackgroundColor("FFFF00") ``` -------------------------------- ### Get Raw XML for a Row Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-table.md Retrieves the underlying raw XML structure of a Row object. This is useful for advanced manipulation or inspection. ```go row := table.AddRow() rawXML := row.X() ``` -------------------------------- ### Create a PowerPoint Presentation Source: https://github.com/carmel/gooxml/blob/master/_autodocs/00-START-HERE.md Quickly create a new PowerPoint presentation, add a slide with a title, add text to the title, and save it to a file. ```go pres := presentation.New() slide := pres.AddSlide() title := slide.AddTitle() title.AddParagraph().AddRun().AddText("My Presentation") pres.SaveToFile("output.pptx") ``` -------------------------------- ### Get Raw Table XML Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-table.md Retrieves the underlying raw XML structure of a table. Use this when direct XML manipulation is required. ```go table := doc.AddTable() rawXML := table.X() ``` -------------------------------- ### Open a Document as a Template Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-document.md Opens a Word document to be used as a template. Modifications can be made, and the document can be saved as a new file without altering the original template. ```go doc, err := document.OpenTemplate("invoice-template.docx") if err != nil { panic(err) } // Modify and save as new file doc.SaveToFile("invoice-2024.docx") ``` -------------------------------- ### Set Document Background Color using Raw Types Source: https://github.com/carmel/gooxml/blob/master/README.md Demonstrates how to manually set a document's background color by accessing and modifying the raw CT_Background element when the library's API does not directly support it. Requires importing necessary packages. ```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 Font Color Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-cell-and-row.md Sets the font color using a hex RGB value. For example, "FF0000" for red. ```go style := cell.Style() style.SetFontColor("FF0000") // Red style.SetFontColor("00FF00") // Green ``` -------------------------------- ### Save Presentation to io.Writer Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Writes the presentation to an io.Writer in the Office Open XML (.pptx) zip format. This is useful for saving to network streams or in-memory buffers. ```go file, err := os.Create("output.pptx") if err != nil { panic(err) } deffer file.Close() if err := pres.Save(file); err != nil { panic(err) } ``` -------------------------------- ### Set Category Axis Title Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-chart.md Sets the title for a category axis. Use this to label the axis clearly, for example, with time periods. ```go axis := chart.CategoryAxis() axis.SetTitle("Months") ``` -------------------------------- ### Add Page Break Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Inserts a page break immediately after the current run, forcing subsequent content to start on a new page. ```go run := para.AddRun() run.AddText("End of page") run.AddPageBreak() ``` -------------------------------- ### Get Shape Text Content Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Retrieves all text content from a shape as a single concatenated string. Useful for reading the shape's text. ```go shape := slide.AddTitle() text := shape.Text() ``` -------------------------------- ### Format a Spreadsheet Cell Source: https://github.com/carmel/gooxml/blob/master/_autodocs/INDEX.md Shows how to set cell content and apply formatting like bold text and background color to a spreadsheet cell. ```go cell := sheet.Cell("A1") cell.SetString("Value") style := cell.Style() style.SetBold(true) style.SetBackgroundColor("FFFF00") ``` -------------------------------- ### Create Image from File Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/common-and-utilities.md Use `ImageFromFile` to create an image object from a local file path. This image can then be added to documents or used in inline drawings. ```go img := common.ImageFromFile("photo.png") doc.AddImage(img) para := doc.AddParagraph() run := para.AddRun() run.AddDrawingInline(img) ``` -------------------------------- ### Get Sheet Name Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-workbook.md Use Name to retrieve the current name of a spreadsheet sheet. This is useful for verifying or displaying the sheet's identifier. ```go sheet := wb.AddSheet() sheet.SetName("My Data") name := sheet.Name() // "My Data" ``` -------------------------------- ### Get Cell by Column Index Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-cell-and-row.md Access a specific cell within a row using its 1-based column index. If the cell does not exist, it will be created. ```go row := sheet.Row(1) cell := row.Cell(1) // Column A cell.SetString("Value") ``` -------------------------------- ### Saving Presentations with Error Handling Source: https://github.com/carmel/gooxml/blob/master/_autodocs/errors.md Shows how to handle errors when saving presentation files using pres.Save() and pres.SaveToFile(). This includes managing potential I/O errors or validation problems. ```Go // Saving presentations err := pres.Save(file) if err != nil { // Handle: I/O error, validation error } err := pres.SaveToFile("output.pptx") if err != nil { // Handle: file creation error, I/O error } ``` -------------------------------- ### Get Text Content of a Run Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Retrieves the plain text content of a run. This method is useful for reading or displaying the text within a run. ```go run := para.AddRun() run.AddText("Sample") text := run.String() // "Sample" ``` -------------------------------- ### Get Raw XML Document Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-document.md Retrieves the underlying raw XML structure of the document, allowing for direct manipulation of ECMA-376 specification elements. ```APIDOC ## Get Raw XML Document ### Description Retrieves the underlying raw XML structure of the document, allowing for direct manipulation of ECMA-376 specification elements. ### Method `func (d *Document) X() *wml.Document` ### Returns - `*wml.Document` — Raw Office Open XML structure from the schema package ### Example ```go rawDoc := doc.X() // Can now access and modify raw XML structures ``` ``` -------------------------------- ### Configure Document Core Properties Source: https://github.com/carmel/gooxml/blob/master/_autodocs/configuration.md Modify metadata fields like title, creator, subject, keywords, and description when creating a new document. ```go doc := document.New() // Modify metadata doc.CoreProperties.SetTitle("Document Title") doc.CoreProperties.SetCreator("Author Name") doc.CoreProperties.SetSubject("Subject") doc.CoreProperties.SetKeywords("keywords, tags") doc.CoreProperties.SetDescription("Document description") // Add content para := doc.AddParagraph() para.AddRun().AddText("Content") ``` -------------------------------- ### Get All Tables Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-document.md Returns a slice of all tables present in the document, including any tables nested within cells. This allows for iterating and processing all tables. ```go tables := doc.Tables() for _, table := range tables { rows := table.Rows() fmt.Printf("Table with %d rows\n", len(rows)) } ``` -------------------------------- ### Set Background Color Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-cell-and-row.md Sets the cell background color using a hex color code. For example, "FFFF00" for yellow. ```go style := cell.Style() style.SetBackgroundColor("FFFF00") // Yellow style.SetBackgroundColor("E2EFDA") // Light green ``` -------------------------------- ### Set Font Name and Size Source: https://github.com/carmel/gooxml/blob/master/_autodocs/configuration.md Configure font names and sizes for document runs, spreadsheet cells, and presentations. Font names should be available on the target system. Font size is specified in points. ```go // Document props := run.Properties() props.SetFontName("Arial") props.SetFontName("Times New Roman") props.SetFontName("Courier New") props.SetFontSize(12) // Points // Spreadsheet style := cell.Style() style.SetFontName("Calibri") style.SetFontSize(11) // Presentation props := run.Properties() props.SetFontName("Arial") ``` -------------------------------- ### Create Uint64 Pointer Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/common-and-utilities.md Creates a pointer to a uint64 value for optional fields. ```go gooxml.Uint64(200) ``` -------------------------------- ### Get Raw XML of a Shape Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Retrieves the underlying raw XML structure of a shape. Use this when direct manipulation of the Office Open XML is required. ```go shape := slide.AddTitle() rawXML := shape.X() ``` -------------------------------- ### Set Highlight Color Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Sets the highlight color for the text. Accepts color names as strings. ```go props := run.Properties() props.SetHighlight("yellow") ``` -------------------------------- ### Validate and Save Document Source: https://github.com/carmel/gooxml/blob/master/_autodocs/errors.md Before saving a document, validate its contents to catch potential issues. This pattern demonstrates creating a new document, adding content, validating, and then saving. ```go doc := document.New() para := doc.AddParagraph() para.AddRun().AddText("Content") // Validate before save if err := doc.Validate(); err != nil { log.Printf("Validation warning: %v", err) } // Save if err := doc.SaveToFile("output.docx"); err != nil { log.Fatalf("Save failed: %v", err) } ``` -------------------------------- ### Create Uint32 Pointer Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/common-and-utilities.md Creates a pointer to a uint32 value for optional fields. ```go gooxml.Uint32(20) ``` -------------------------------- ### Add Line Break Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Inserts a line break within the run, causing the following text to appear on a new line without starting a new paragraph. ```go run := para.AddRun() run.AddText("Line 1") run.AddLineBreak() run.AddText("Line 2") ``` -------------------------------- ### Spreadsheet Creation and Loading Source: https://github.com/carmel/gooxml/blob/master/_autodocs/QUICK-INDEX.md Functions for creating new workbooks and opening existing ones. ```APIDOC ## Spreadsheet Functions ### Creation and Loading - **New()** - **Description**: Creates a new, empty workbook. - **Signature**: `func New() *Workbook` - **Returns**: A pointer to a new `Workbook` object. - **Open(filename string)** - **Description**: Opens an existing spreadsheet file. - **Signature**: `func Open(filename string) (*Workbook, error)` - **Parameters**: - **filename** (string) - Required - The path to the spreadsheet file. - **Returns**: A pointer to the `Workbook` object and an error if opening fails. ``` -------------------------------- ### Set Value Axis Minimum Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-chart.md Configures the minimum value displayed on a value axis. Essential for setting the scale of numerical data, typically starting from zero. ```go axis := chart.ValueAxis() axis.SetMinimum(0) ``` -------------------------------- ### Add Header to Document Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-document.md Creates a new header and associates it with the document. The header must be assigned to a section to be displayed. ```go header := doc.AddHeader() para := header.AddParagraph() run := para.AddRun() run.AddText("Page Header") ``` -------------------------------- ### Get Raw XML Structure Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Retrieves the underlying raw XML structure of the presentation, represented by `*pml.Presentation`. This can be useful for advanced manipulation or inspection of the presentation's XML. ```APIDOC ## `func (p *Presentation) X() *pml.Presentation` ### Description Returns the underlying raw XML structure. ### Returns - `*pml.Presentation` — Raw Office Open XML presentation type ``` -------------------------------- ### Apply Shape Formatting Source: https://github.com/carmel/gooxml/blob/master/_autodocs/README.md Applies fill color and border properties to a shape in a presentation. ```go // Shape formatting (presentation) shape := slide.AddRectangle(Inch(1), Inch(1), Inch(2), Inch(2)) props := shape.Properties() props.SetFill(color.RGB(255, 0, 0)) props.SetLine(color.RGB(0, 0, 0), Point(2)) ``` -------------------------------- ### Get All Merged Cell Ranges Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-workbook.md Use MergedCells to retrieve a list of all currently merged cell ranges within a sheet. Each merged cell can be accessed via its reference. ```go sheet := wb.AddSheet() for _, merge := range sheet.MergedCells() { fmt.Printf("Merged: %s\n", merge.Reference()) } ``` -------------------------------- ### Set Cell Background Color Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-table.md Use this method to set the cell background color using a hex code. Call `cell.Properties()` to get the cell properties object. ```Go props := cell.Properties() props.SetBackground("CCCCCC") // Light gray ``` -------------------------------- ### Run.Properties Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Returns the properties object for formatting the run. Use this object to apply styles like bold, font size, and color. ```APIDOC ## Run.Properties ### Description Returns the properties object for formatting the run. Use this object to apply styles like bold, font size, and color. ### Method `func (r Run) Properties() RunProperties` ### Returns - `RunProperties` — Formatting configuration object ### Example ```go run := para.AddRun() props := run.Properties() props.SetBold(true) props.SetFontSize(24) // 12pt = 24 half-points props.SetColor("FF0000") // Red run.AddText("Bold red text") ``` ``` -------------------------------- ### Create Int64 Pointer Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/common-and-utilities.md Creates a pointer to an int64 value for optional fields. ```go gooxml.Int64(100) ``` -------------------------------- ### Parsing Cell Ranges in Gooxml Source: https://github.com/carmel/gooxml/blob/master/_autodocs/errors.md Shows examples of valid and invalid cell range formats for the `sheet.MergeCells()` function. Invalid ranges require both row and column information. ```go // Parsing ranges sheet.MergeCells("A1", "C5") // Valid sheet.MergeCells("A", "C5") // Invalid: row required ``` -------------------------------- ### Save Presentation to Writer Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/presentation-presentation.md Writes the entire presentation to an `io.Writer` in the Office Open XML (.pptx) zip format. This is useful for saving to network streams or other custom writer destinations. ```APIDOC ## `func (p *Presentation) Save(w io.Writer) error` ### Description Writes the presentation to an io.Writer in the Office Open XML (.pptx) zip format. ### Parameters #### Path Parameters - **w** (io.Writer) - Required - Destination writer for the .pptx data ### Returns - `error` — Error if validation or serialization fails ### Throws - `error` — If XML marshaling or zip operations fail ``` -------------------------------- ### Saving Documents with Error Handling Source: https://github.com/carmel/gooxml/blob/master/_autodocs/errors.md Illustrates error handling for saving documents to a file or a file path using doc.Save() and doc.SaveToFile(). Potential errors include I/O issues or validation failures. ```Go // Saving documents err := doc.Save(file) if err != nil { // Handle: I/O error, validation error } err := doc.SaveToFile("output.docx") if err != nil { // Handle: file creation error, I/O error } ``` -------------------------------- ### Get Cell Value as Number Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-cell-and-row.md Attempts to retrieve the cell's value as a float64. It will attempt to parse the value if it's stored as a string. Returns an error if parsing fails. ```go cell := sheet.Cell("A1") cell.SetString("42.5") num, err := cell.GetValueAsNumber() if err == nil { fmt.Printf("Number: %f\n", num) } ``` -------------------------------- ### Presentation Methods Source: https://github.com/carmel/gooxml/blob/master/_autodocs/QUICK-INDEX.md Methods for managing the overall presentation, including accessing its internal structure, adding/removing slides, and saving. ```APIDOC ## X() ### Description Returns the internal presentation object. ### Signature `func (p *Presentation) X() *pml.Presentation` ### Returns `*pml.Presentation` - The internal presentation object. ``` ```APIDOC ## AddSlide() ### Description Adds a new, blank slide to the presentation and returns it. ### Signature `func (p *Presentation) AddSlide() Slide` ### Returns `Slide` - The newly added Slide object. ``` ```APIDOC ## Slides() ### Description Returns a slice containing all slides in the presentation. ### Signature `func (p *Presentation) Slides() []Slide` ### Returns `[]Slide` - A slice of all Slide objects in the presentation. ``` ```APIDOC ## SlideCount() ### Description Returns the total number of slides in the presentation. ### Signature `func (p *Presentation) SlideCount() int` ### Returns `int` - The number of slides. ``` ```APIDOC ## RemoveSlide() ### Description Removes a slide from the presentation at the specified index. ### Signature `func (p *Presentation) RemoveSlide(index int) error` ### Parameters #### Path Parameters - **index** (int) - Required - The index of the slide to remove. ``` ```APIDOC ## Save() ### Description Saves the presentation to the provided `io.Writer`. ### Signature `func (p *Presentation) Save(w io.Writer) error` ### Parameters #### Path Parameters - **w** (io.Writer) - Required - The writer to save the presentation to. ``` ```APIDOC ## SaveToFile() ### Description Saves the presentation to a file at the specified path. ### Signature `func (p *Presentation) SaveToFile(path string) error` ### Parameters #### Path Parameters - **path** (string) - Required - The file path to save the presentation. ``` ```APIDOC ## ValidateSlides() ### Description Validates the slides within the presentation for correctness. ### Signature `func (p *Presentation) ValidateSlides() error` ``` -------------------------------- ### Saving Spreadsheets with Error Handling Source: https://github.com/carmel/gooxml/blob/master/_autodocs/errors.md Demonstrates error handling for saving spreadsheet workbooks to a file or a file path using wb.Save() and wb.SaveToFile(). Errors can occur due to I/O problems or validation issues. ```Go // Saving workbooks err := wb.Save(file) if err != nil { // Handle: I/O error, validation error } err := wb.SaveToFile("output.xlsx") if err != nil { // Handle: file creation error, I/O error } ``` -------------------------------- ### Get Cell Reference Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-cell-and-row.md Returns the cell reference string (e.g., "A1", "B10"). This is typically set automatically when the cell is created or accessed. ```go cell := sheet.Cell("A5") ref := cell.Reference() // "A5" ``` -------------------------------- ### New Document Creation Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-document.md Creates a new, empty Word document with default settings. This is the primary entry point for generating new .docx files. ```APIDOC ## New Document Creation ### Description Creates a new, empty Word document with default settings. This is the primary entry point for generating new .docx files. ### Method `func New() *Document` ### Returns - `*Document` — A newly initialized document with standard Office document structure ### Example ```go package main import ( "os" "github.com/carmel/gooxml/document" ) func main() { doc := document.New() // Document is ready for content doc.SaveToFile("output.docx") } ``` ``` -------------------------------- ### Open and Modify Document Source: https://github.com/carmel/gooxml/blob/master/_autodocs/README.md Opens an existing DOCX document, allows content modification, and saves it to a new file. ```go // Open existing document doc, err := document.Open("template.docx") if err != nil { panic(err) } defer doc.Close() // Modify content para := doc.AddParagraph() para.AddRun().AddText("New content") // Save as new file (preserves original) doc.SaveToFile("output.docx") ``` -------------------------------- ### Set Paragraph Style Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/document-paragraph-and-run.md Applies a specific style identifier to the paragraph. An empty string will remove any existing style. ```go para := doc.AddParagraph() para.SetStyle("Heading1") run := para.AddRun() run.AddText("Chapter Title") ``` -------------------------------- ### Create Image from Bytes Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/common-and-utilities.md Use `ImageFromBytes` to create an image object from raw byte data. Specify the image format (e.g., "png", "jpeg") and the byte slice containing the image data. ```go data := []byte{/* PNG data */} img := common.ImageFromBytes("png", data) doc.AddImage(img) ``` -------------------------------- ### Set Error Message Source: https://github.com/carmel/gooxml/blob/master/_autodocs/api-reference/spreadsheet-features.md Defines an error message that is displayed when a user enters invalid data into a validated cell. This helps inform users about incorrect entries and guides them to correct them. ```go validation := cell.AddValidation() validation.SetErrorMessage("Invalid Entry", "Please select from the list") ```