xlBuf.AddColumnPr('Column Header 1',FALSE,xlBuf."Cell Type"::Text,''); xlBuf.AddColumnPr('Column Header 2',FALSE,xlBuf."Cell Type"::Text,''); xlBuf.AddColumnPr('Column Header 3',FALSE,xlBuf."Cell Type"::Text,''); xlBuf.NewRow; xlBuf.AddColumnPr(100,FALSE,xlBuf."Cell Type"::Number,''); xlBuf.AddColumnPr(200,FALSE,xlBuf."Cell Type"::Number,'Unlocked'); // Allow edit cell xlBuf.AddColumnPr('=A2+B2',TRUE,xlBuf."Cell Type"::Number,'Formula Hidden'); // Hide formula // Password is Pass xlBuf.ProtectSheet( 'HEdftSyT8KPWhGzOmzHYTecQnB0jjcqSiJ+BT4dVSAO84CSydiTxV8Ko7KnqHmIWz0ofd1i9qSnqwibCYhNx8g==', 'rrvL3+SaHgL5shjuB9BePg==', 100000); xlBuf.CreateBookAndOpenExcel('','Sheet1','',COMPANYNAME,USERID);
</sheetData> <sheetProtection algorithmName="SHA-512" hashValue="cSeSDt4Mhl1M12H8JGJ/JZ1XZ4oWSqqJfrq0Hh3ggPRZS7d/bu2S4lld0JlwYqTx8wK9X6tYKZi55fmtzT8Agw==" saltValue="IzuINz/i6RcBz6ECeI1Q1g==" spinCount="100000" sheet="1" objects="1" scenarios="1"/>
Answers
RIS Plus, LLC
Excel buffer looks the same, but we have a lot of Excel objects available.
Since it already uses openxml, I am hoping to find a lock function using it.
Otherwise, it looks like I need to use interop which I lack some working examples on how to use in C/AL.
http://mibuso.com/blogs/davidmachanick/
I did it in Nav 2017, you can try to transfer it to your system.
https://forum.mibuso.com/discussion/73152/
You will have to transfer all functions where global variables FreezePaneRowNo and FreezePaneColNo are used.
And call AddFreezePane() before WritheSheet().
I need to add protect sheet and lock cells - neither of which are clear to me how to do with NAV functions.
If you have time, can you tell me how to add these functions please.
http://mibuso.com/blogs/davidmachanick/
I added functions to protect sheet, you can find updated version on GitHub.
Below is an example how to use it:
OpenXML stores password in encrypted strings - HashValue and saltValue.
Here is a function to convert password string to these values:
https://www.codeproject.com/Questions/5369775/Openxml-excel-lock-cells
I didn't implement it in this version.
But there is another way to get these values - create new workbook, protect sheet with password and save it.
Then change file extension from xlsx to zip and open it.
In the folder xl\worksheets will be sheet1.xml, need to open it and find sheetProtection node.
Here you can find HashValue, SaltValue and SpinCount - it is your encrypted password, which you have to pass into ProtectSheet function.
(I am probably 2 years away from their move to BC.)
http://mibuso.com/blogs/davidmachanick/