【问题标题】:Locking / protecting a cell or column in Jasper iReport在 Jasper iReport 中锁定/保护单元格或列
【发布时间】:2014-11-18 16:31:21
【问题描述】:

我正在尝试锁定从 Jasper iReport 创建的 Excel 工作表中的列/单元格,因为我们的客户不希望用户能够更新公式。我在这方面找不到太多东西。

我添加了我在配置参考 (http://jasperreports.sourceforge.net/config.reference.html#net.sf.jasperreports.export.xls.cell.locked) 中找到的锁定属性,尽管它不会阻止在导出的工作表上编辑列中的单元格。

<jr:column width="100">
    <jr:detailCell style="table" height="20" rowSpan="1">
        <textField>
            <reportElement style="table" x="0" y="0" width="100" height="20">
                <property name="net.sf.jasperreports.export.xls.formula" value="INDIRECT(ADDRESS(ROW(),4))"/>
                <property name="net.sf.jasperreports.export.xls.cell.locked" value="true"/>
            </reportElement>
        </textField>
    </jr:detailCell>
</jr:column>

配置参考还说设置“只有在封闭的工作表受到保护时才有效”。我使用密码属性向工作表添加了密码,但这会导致整个工作表受到保护。

<property name="net.sf.jasperreports.export.xls.password" value="password" />

在整个工作表受到保护的情况下,我尝试将需要更新的字段的锁定属性设置为 false。但我仍然无法更新它们,因为整个工作表都受到保护。

关于如何保护某些单元格或列而不是其他单元格或列的任何想法?

【问题讨论】:

    标签: jasper-reports protected locked


    【解决方案1】:

    我昨天在 jaspersoft 工作室遇到了同样的问题。可能是我来晚了,你已经自己解决了这个问题。在这种情况下,只是为了帮助像我们这样的人,这里是这样做的方法。

    似乎一旦我们在工作表级别设置了密码,默认情况下所有单元格都被锁定(再想一想,这似乎很明显)。因此,如果我们想解锁一个单元格,我们必须明确提及。

    <property name="net.sf.jasperreports.export.xls.cell.locked" value="false"/>
    

    因此,下面的代码将生成一个 Excel 表格,其中“Static Text”单元格将被锁定,而“Static Text22”单元格将被解锁。希望这个例子能帮助到其他人,他们不必像我一样绕来绕去。

    <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3bff4add-3bc7-49b8-acd4-0ec822191576">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <property name="net.sf.jasperreports.export.xls.password" value="test_password"/>
    <queryString>
    <![CDATA[]]>
    </queryString>
    <background>
    <band splitType="Stretch"/>
    </background>
    <title>
    <band height="79" splitType="Stretch">
    <staticText>
    <reportElement x="123" y="2" width="100" height="30" uuid="c9f7abf8-2ed4-44c3-abf5-84fda5d190f4"/>
    <text><![CDATA[Static Text]]></text>
    </staticText>
    <staticText>
    <reportElement x="223" y="2" width="100" height="30" uuid="d95b84d7-5d1b-4919-b4f0-82a30c9effd6">
    <property name="net.sf.jasperreports.export.xls.cell.locked" value="false"/>
    </reportElement>
    <text><![CDATA[Static Text22]]></text>
    </staticText>
    </band>
    </title>
    </jasperReport>
    

    【讨论】:

    • 谢谢!刚试了一下,它对我有用。在我的问题中,听起来我尝试过这个,但我不知道我做错了什么!
    猜你喜欢
    • 2013-02-22
    • 2016-02-20
    • 1970-01-01
    • 2019-03-28
    • 2019-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多