Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to password protect an xlsx #245

Closed
MassimoMessina opened this issue Mar 9, 2019 · 4 comments
Closed

how to password protect an xlsx #245

MassimoMessina opened this issue Mar 9, 2019 · 4 comments
Assignees

Comments

@MassimoMessina
Copy link

Description

I'm not able to set a password to open a workbook. If we save a workbook, the function Save() is producing a zip file that is not in the format required for the protected xlsx. Anyhow, I tried to protect using the setPassword() but it doesn't make the trick.

Expected Behavior

Actual Behavior

Please include a reproducible code snippet or document attachment that
demonstrates the issue.

            Ss = spreadsheet.New()
	Sp:= Ss.Protection()
	Sp.SetPassword("testpsw")
	Wrapped = Ss.StyleSheet.AddCellStyle()
	Wrapped.SetWrapped(true)
	Wrapped.SetVerticalAlignment(sml.ST_VerticalAlignmentCenter)

	sheet := Ss.AddSheet()
	sheet.SetName(mgr.Name)
	sheet.Column(1).SetWidth(4 * measurement.Inch)
	sheet.Column(2).SetWidth(2 * measurement.Inch)
	sheet.Column(2).SetWidth(2 * measurement.Inch)
	sheet.Column(2).SetWidth(2 * measurement.Inch)

	// Write Headers
	row := sheet.AddRow()
	cellA := row.AddCell()
	cellA.SetStyle(Wrapped)
	cellA.SetString("Name")

	if err := Ss.Validate(); err != nil {
		log.Fatalf("error validating sheet: %s", err)
	}

	ofil := "testpsw.xlsx"
	Ss.SaveToFile(ofil)
	log.Printf("\nData saved into:%s\n", ofil)
@gunnsth gunnsth self-assigned this Apr 3, 2019
@gunnsth gunnsth assigned nkryuchkov and unassigned gunnsth Apr 15, 2019
@nkryuchkov
Copy link
Contributor

nkryuchkov commented May 6, 2019

After a bit of research I found out that the password protection right now works according to the ooxml specification, and, indeed, this does not change the file format itself. However with the current version you may prevent the sheets from being edited. To achieve this you should add the protection to each sheet in this fashion:

sheet := Ss.AddSheet()
sp := sheet.Protection()
sp.SetPassword("1234")
sp.LockObject(true)
sp.LockSheet(true)

Full password protection is related to #276

@gunnsth
Copy link
Contributor

gunnsth commented May 6, 2019

@MassimoMessina Does that make sense?

@MassimoMessina
Copy link
Author

MassimoMessina commented May 7, 2019 via email

@gunnsth
Copy link
Contributor

gunnsth commented May 7, 2019

That is not possible at the present. It requires implementation of #276.

@gunnsth gunnsth closed this as completed May 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants