Skip to content

Commit

Permalink
Merge pull request #12 from unidoc/rc-v1.11.0
Browse files Browse the repository at this point in the history
v1.11.0: Add spreadsheet/cell-protection example and update modules
  • Loading branch information
gunnsth committed May 31, 2021
2 parents 7473499 + 05c525e commit c79533b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.13

require (
github.com/go-ole/go-ole v1.2.5
github.com/unidoc/unioffice v1.10.0
github.com/unidoc/unipdf/v3 v3.23.0
github.com/unidoc/unioffice v1.11.0
github.com/unidoc/unipdf/v3 v3.25.0
golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df h1:1RV3lxQ6L6xGFNhngp
github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8=
github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a h1:RLtvUhe4DsUDl66m7MJ8OqBjq8jpWBXPK6/RKtqeTkc=
github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZVpZFTvDey3zxUkSgPJZEX33tDgU/QIA0IzCUw=
github.com/unidoc/unioffice v1.10.0 h1:CDpbd7szRgl8hFZE0XPKOOknHSGGu0q9NAPv+7dK1DU=
github.com/unidoc/unioffice v1.10.0/go.mod h1:8QJAWaP6ZNjyoONjKXmzbM07/nDDgHpj5uO7xaBH6Ok=
github.com/unidoc/unioffice v1.11.0 h1:WqNDcI+vOtB3waV1pd2hM68ajYRZ50e4DidakQQsWWM=
github.com/unidoc/unioffice v1.11.0/go.mod h1:8QJAWaP6ZNjyoONjKXmzbM07/nDDgHpj5uO7xaBH6Ok=
github.com/unidoc/unipdf/v3 v3.22.0/go.mod h1:WdRz3hVhi/M0jFGXhsT5/9FDyRfga6KgI2ZQqjiOXaM=
github.com/unidoc/unipdf/v3 v3.23.0 h1:CVUktNhZo1Fo1M137Jj73gp5h6FwR8b+dKrfc3teeb8=
github.com/unidoc/unipdf/v3 v3.23.0/go.mod h1:WdRz3hVhi/M0jFGXhsT5/9FDyRfga6KgI2ZQqjiOXaM=
github.com/unidoc/unipdf/v3 v3.25.0 h1:OJmfZg2BJdA10oOcb6leyi3lDjeDf5SV1OFlBrBc5+4=
github.com/unidoc/unipdf/v3 v3.25.0/go.mod h1:WdRz3hVhi/M0jFGXhsT5/9FDyRfga6KgI2ZQqjiOXaM=
github.com/unidoc/unitype v0.2.1 h1:x0jMn7pB/tNrjEVjy3Ukpxo++HOBQaTCXcTYFA6BH3w=
github.com/unidoc/unitype v0.2.1/go.mod h1:mafyug7zYmDOusqa7G0dJV45qp4b6TDAN+pHN7ZUIBU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
Binary file added spreadsheet/cell-protection/cell-protection.xlsx
Binary file not shown.
61 changes: 61 additions & 0 deletions spreadsheet/cell-protection/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2017 FoxyUtils ehf. All rights reserved.
package main

import (
"fmt"

"github.com/unidoc/unioffice/common/license"
"github.com/unidoc/unioffice/measurement"
"github.com/unidoc/unioffice/spreadsheet"
"github.com/unidoc/unioffice/spreadsheet/reference"
)

const licenseKey = `
-----BEGIN UNIDOC LICENSE KEY-----
Free trial license keys are available at: https://unidoc.io/
-----END UNIDOC LICENSE KEY-----
`

func init() {
err := license.SetLicenseKey(licenseKey, `Company Name`)
if err != nil {
panic(err)
}
}

func main() {
ss := spreadsheet.New()
defer ss.Close()

sheet := ss.AddSheet()
var width = measurement.Distance(100)

// Set style of cell to be not protected and not hidden
cellStyle1 := ss.StyleSheet.AddCellStyle()
cellStyle1.SetProtection(false, false)
// Apply cellStyle1 to range of cells A1:D10 with looping.
from, to, err := reference.ParseRangeReference("A1:D10")
if err != nil {
panic(err)
}
for rowIdx := from.RowIdx; rowIdx <= to.RowIdx; rowIdx++ {
for colIdx := from.ColumnIdx; colIdx <= to.ColumnIdx; colIdx++ {
currentCell := reference.IndexToColumn(colIdx)
sheet.Row(rowIdx).Cell(currentCell).SetStyle(cellStyle1)
}
}

// Apply cellStyle1 to column F.
sheet.Column(6).SetStyle(cellStyle1)
sheet.Column(6).SetWidth(width)

// Add protection to sheet and lock it.
sp := sheet.Protection()
sp.LockSheet(true)
// Set password for unlocking sheet.
sp.SetPassword("unioffice")

if err := ss.SaveToFile("cell-protection.xlsx"); err != nil {
fmt.Println(err)
}
}

0 comments on commit c79533b

Please sign in to comment.