gpt4 book ai didi

excel - 如何创建基于宏的模板?

转载 作者:行者123 更新时间:2023-12-03 03:34:19 26 4
gpt4 key购买 nike

导出到excel时是否可以在jrxml中添加宏?

我找不到任何文档,我唯一能找到的是 JasperSoft 社区上的这个问题,Excel macro and pivot tables .

最佳答案

net.sf.jasperreports.export.xlsx.macro.template的帮助下,可以使用(MS Excel类型)从外部文件添加MS Excel宏报告的属性。

可以使用 xltmxlsm 类型的

示例

让我们尝试添加简单的来为事件单元格添加注释。此将存储在macro.xlsm文件中。

的内容(示例*):

Sub add_comment()
Dim cmt As Comment
Dim str As String
On Error Resume Next

str = "Value: " + ActiveCell.Text
Set cmt = ActiveCell.Comment
If cmt Is Nothing Then
ActiveCell.AddComment _
Text:=str
Set cmt = ActiveCell.Comment
End If

With cmt
.Shape.AutoShapeType = msoShapeRoundedRectangle
.Shape.TextFrame.Characters.Font.Name = "Tahoma"
.Shape.TextFrame.Characters.Font.Size = 8
.Shape.TextFrame.Characters.Font.ColorIndex = 2
.Shape.Line.ForeColor.RGB = RGB(0, 0, 0)
.Shape.Line.BackColor.RGB = RGB(255, 255, 255)
.Shape.Fill.Visible = msoTrue
.Shape.Fill.ForeColor.RGB = RGB(58, 82, 184)
.Shape.Fill.OneColorGradient msoGradientDiagonalUp, 1, 0.23
End With

SendKeys "+{F2}" 'opens comment for editing
End Sub

jrxml 文件(报告模板)将是:

<?xml version="1.0" encoding="UTF-8"?>
<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="Macro sample" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<property name="net.sf.jasperreports.export.xlsx.macro.template" value="macro.xlsm"/>
<title>
<band height="158">
<staticText>
<reportElement x="0" y="0" width="595" height="30"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[Long title]]></text>
</staticText>
<staticText>
<reportElement x="0" y="30" width="595" height="128"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="SansSerif" size="18" isBold="true"/>
</textElement>
<text><![CDATA[Some text. This is a sample of using Macros]]></text>
</staticText>
</band>
</title>
</jasperReport>

我们使用 net.sf.jasperreports.export.xlsx.macro.template 属性将宏模板中的脚本包含到生成的报告中。

输出结果

我们可以在Jaspersoft Studio中生成MS Excel格式的报告:

Exporting report at JSS

打开生成的xls文件后,我们可以运行嵌入式:

Running Macro at Excel

运行的结果是创建了新的彩色注释:

Created comment at Excel file

<小时/>

更多信息请访问Advanced Excel Features发布。

关于excel - 如何创建基于宏的模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44240681/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com