问题描述
我使用cfspreadsheet创建一个电子表格对象。想要使一些单个单元格受保护(只读)。请让我知道是否有人尝试过这个。
I am creating a spreadsheet object using cfspreadsheet. Would like to make some of the individual cells as protected (read-only). Please let me know if anybody has tried this before.
我尝试将单元格格式锁定,但似乎没有工作。下面是示例代码:
I did try putting cell format as locked but it did not seems to work. Here is the sample code:
<cfset a = spreadsheetnew()>
<cfset format1 = structNew()>
<cfset format1.locked=true>
<cfset SpreadsheetFormatCell(a,format1,1,1)>
<cfspreadsheet action="write" filename="#expandpath('.')#/test.xls" name="a" overwrite="true">
谢谢。
推荐答案
锁定单元格不会执行任何操作,即使用cfspreadsheet的密码
属性。但这样做有一些负面影响...
Locking a cell does nothing unless the sheet is protected ie using cfspreadsheet's password
attribute. But doing so has some negative side effects ...
保护薄片锁定所有单元格。这意味着你必须通过应用格式解锁一切。理论上你可以解锁整个工作表:
Protecting the sheet locks all cells. That means you essentially have to "unlock" everything else by applying a format. In theory you could just unlock the entire sheet:
<cfset SpreadsheetFormatCellRange (sheet, {locked=false}, 1, 1, maxRow, maxCol)>
但是,在 片。因此,如果您将文件读入查询,查询将包含〜65,536行和256列。即使你只显式地填充了几个单元格。
However, that has the nasty effect of populating every single cell in the sheet. So if you read the file into a query, the query would contain ~65,536 rows and 256 columns. Even if you only populated a few cells explicitly.
锁定功能更适合于您希望除了几个单元格(不是相反的)之外的所有内容都被锁定的情况。
The lock feature is better suited to cases where you want everything to be locked except a few cells (not the reverse). Unless that is what you are doing, I probably would not bother with it, given all the negative side effects.
副作用示例
<cfset testFile = "c:/test.xls">
<cfset sheet = spreadsheetNew()>
<!--- only unlocking 100 rows to demonstrate --->
<cfset SpreadsheetFormatCellRange (sheet, {locked=false}, 1, 1, 100, 10)>
<!--- populate two cells --->
<cfset SpreadsheetSetCellValue(sheet,"LOCKED",1,1)>
<cfset SpreadsheetSetCellValue(sheet,"UNLOCKED",2,1)>
<!--- make one cell locked --->
<cfset SpreadsheetFormatCell(sheet, {locked=true}, 1, 1)>
<cfspreadsheet action="write"
name="sheet"
fileName="#testFile#"
password=""
overwrite="true" >
<!--- now see it is filled with empty cells --->
<cfspreadsheet action="read"
query="sheetData"
src="#testFile#" >
<cfdump var="#sheetData#" label="Lots of empty cells" />
这篇关于如何创建带受保护单元格的cfspreadsheet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!