Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexJarrah committed Jan 1, 2024
0 parents commit 184fcc6
Show file tree
Hide file tree
Showing 6 changed files with 592 additions and 0 deletions.
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2023 Alex Jarrah

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# go-ods

## Overview

go-ods is a Go package designed to simplify reading and writing ODS (OpenDocument Spreadsheet) files. With this library, you can seamlessly work with ODS files in your Go applications, providing support for common spreadsheet operations.

## Features

- Read ODS Files: Easily parse and extract data from ODS files.
- Write ODS Files: Update ODS files with new/updated data.
- Cell Manipulation: Perform operations on individual cells, such as setting values, formatting, and more.
- Sheet Handling: Manage multiple sheets within a single ODS file effortlessly.

## Installation

To use this go-ods, [install Go](https://go.dev) and run:

```bash
go get -u https://github.com/AlexJarrah/go-ods
```

## Usage

```go
package main

import (
"log"

"github.com/AlexJarrah/go-ods"
)

func main() {
// Specify a filepath
const path = "/home/user/Documents/example.ods"

// Reading data from the file
content, files, err := ods.Read(path)
if err != nil {
log.Panic(err)
}
defer files.Close()

// Updating content data in a specific sheet
sheet := content.Body.Spreadsheet.Table[1]
sheet.TableRow[1].TableCell[0].P = "updated value"
sheet.TableRow[2].TableCell[0].P = "updated value"
sheet.TableRow[2].TableCell[3].P = "updated value"

// Writing new data to the file
if err := ods.Write(path, content, files); err != nil {
log.Panic(err)
}
}
```

## License

This project is licensed under the MIT License - see the [LICENSE](https://github.com/AlexJarrah/go-ods/blob/main/LICENSE) file for details.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/AlexJarrah/go-ods

go 1.21.5
32 changes: 32 additions & 0 deletions read.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ods

import (
"archive/zip"
"encoding/xml"
"fmt"
)

func Read(filepath string) (content Content, r *zip.ReadCloser, err error) {
if r, err = zip.OpenReader(filepath); err != nil {
return Content{}, nil, fmt.Errorf("error opening ODS file: %v", err)
}

for _, file := range r.File {
if file.Name != "content.xml" {
continue
}

rc, err := file.Open()
if err != nil {
return Content{}, nil, fmt.Errorf("error opening content.xml: %v", err)
}
defer rc.Close()

if err = xml.NewDecoder(rc).Decode(&content); err != nil {
return Content{}, nil, fmt.Errorf("error decoding content.xml: %v", err)
}
break
}

return content, r, nil
}
Loading

0 comments on commit 184fcc6

Please sign in to comment.