我正在尝试创建一个 stimulsoft 报告,用于在连续进纸标签打印机上打印最多 50 个字符的单行文本,但我无法让报告页面的宽度或高度随单行的长度而变化的文本。
有人成功地做我想做的事情吗?
我已经尝试了 Report/Page/Databand/TextField 对象的 cangrow/autosize 属性可能性的多种排列,以及尝试在各种对象事件中使用 C# 脚本代码将页面宽度设置为文本字段的宽度,但没有运气。
我正在尝试创建一个 stimulsoft 报告,用于在连续进纸标签打印机上打印最多 50 个字符的单行文本,但我无法让报告页面的宽度或高度随单行的长度而变化的文本。
有人成功地做我想做的事情吗?
我已经尝试了 Report/Page/Databand/TextField 对象的 cangrow/autosize 属性可能性的多种排列,以及尝试在各种对象事件中使用 C# 脚本代码将页面宽度设置为文本字段的宽度,但没有运气。
您可以根据页面上的数据量动态设置页面的高度。
首先将页面大小设置为自定义,然后在报表的 EndRender 事件中编写如下脚本:
foreach (StiPage page in this.RenderedPages)
{
double max = 0;
foreach (StiComponent comp in page.GetComponents())
{
if (comp.Bottom > max) max = comp.Bottom;
}
page.PageHeight = max + page.Margins.Top + page.Margins.Bottom;
}
报告样本:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<StiSerializer version="1.02" type="Net" application="StiReport">
<Dictionary Ref="1" type="Dictionary" isKey="true">
<BusinessObjects isList="true" count="0" />
<Databases isList="true" count="0" />
<DataSources isList="true" count="2">
<Products Ref="2" type="DataTableSource" isKey="true">
<Alias>Products</Alias>
<Columns isList="true" count="7">
<value>ProductID,System.Int32</value>
<value>ProductName,System.String</value>
<value>SupplierID,System.Int32</value>
<value>CategoryID,System.Int32</value>
<value>QuantityPerUnit,System.String</value>
<value>UnitPrice,System.Decimal</value>
<value>UnitsInStock,System.Int16</value>
</Columns>
<Dictionary isRef="1" />
<Name>Products</Name>
<NameInSource>Demo.Products</NameInSource>
</Products>
<Categories Ref="3" type="DataTableSource" isKey="true">
<Alias>Categories</Alias>
<Columns isList="true" count="3">
<value>CategoryID,System.Int32</value>
<value>CategoryName,System.String</value>
<value>Description,System.String</value>
</Columns>
<Dictionary isRef="1" />
<Name>Categories</Name>
<NameInSource>Demo.Categories</NameInSource>
</Categories>
</DataSources>
<Relations isList="true" count="1">
<Categories Ref="4" type="DataRelation" isKey="true">
<Alias>Categories</Alias>
<ChildColumns isList="true" count="1">
<value>CategoryID</value>
</ChildColumns>
<ChildSource isRef="2" />
<Dictionary isRef="1" />
<Name>Categories</Name>
<NameInSource>CategoriesProducts</NameInSource>
<ParentColumns isList="true" count="1">
<value>CategoryID</value>
</ParentColumns>
<ParentSource isRef="3" />
</Categories>
</Relations>
<Report isRef="0" />
<Variables isList="true" count="0" />
</Dictionary>
<EndRenderEvent>foreach (StiPage page in this.RenderedPages)
{
double max = 0;
foreach (StiComponent comp in page.GetComponents())
{
if (comp.Bottom > max) max = comp.Bottom;
}
page.PageHeight = max + page.Margins.Top + page.Margins.Bottom;
}
</EndRenderEvent>
<EngineVersion>EngineV2</EngineVersion>
<GlobalizationStrings isList="true" count="0" />
<MetaTags isList="true" count="0" />
<Pages isList="true" count="1">
<Page1 Ref="5" type="Page" isKey="true">
<Border>None;Black;2;Solid;False;4;Black</Border>
<Brush>Transparent</Brush>
<Components isList="true" count="2">
<DataCategories Ref="6" type="DataBand" isKey="true">
<Brush>[157:218:78]</Brush>
<BusinessObjectGuid isNull="true" />
<ClientRectangle>0,0.4,19,0.8</ClientRectangle>
<Components isList="true" count="3">
<DataCategories_CategoryID Ref="7" type="Text" isKey="true">
<Brush>Transparent</Brush>
<CanGrow>True</CanGrow>
<ClientRectangle>0,0,1.8,0.8</ClientRectangle>
<Conditions isList="true" count="0" />
<Font>Arial,8</Font>
<HorAlignment>Center</HorAlignment>
<Margins>0,0,0,0</Margins>
<Name>DataCategories_CategoryID</Name>
<Page isRef="5" />
<Parent isRef="6" />
<Text>{Categories.CategoryID}</Text>
<TextBrush>Black</TextBrush>
<TextOptions>HotkeyPrefix=None, LineLimit=False, RightToLeft=False, Trimming=None, WordWrap=True, Angle=0, FirstTabOffset=40, DistanceBetweenTabs=20,</TextOptions>
<VertAlignment>Center</VertAlignment>
</DataCategories_CategoryID>
<DataCategories_CategoryName Ref="8" type="Text" isKey="true">
<Brush>Transparent</Brush>
<CanGrow>True</CanGrow>
<ClientRectangle>1.8,0,5,0.8</ClientRectangle>
<Conditions isList="true" count="0" />
<Font>Arial,8</Font>
<Margins>0,0,0,0</Margins>
<Name>DataCategories_CategoryName</Name>
<Page isRef="5" />
<Parent isRef="6" />
<Text>{Categories.CategoryName}</Text>
<TextBrush>Black</TextBrush>
<TextOptions>HotkeyPrefix=None, LineLimit=False, RightToLeft=False, Trimming=None, WordWrap=True, Angle=0, FirstTabOffset=40, DistanceBetweenTabs=20,</TextOptions>
<VertAlignment>Center</VertAlignment>
</DataCategories_CategoryName>
<DataCategories_Description Ref="9" type="Text" isKey="true">
<Brush>Transparent</Brush>
<CanGrow>True</CanGrow>
<ClientRectangle>6.8,0,12.2,0.8</ClientRectangle>
<Conditions isList="true" count="0" />
<Font>Arial,8</Font>
<Margins>0,0,0,0</Margins>
<Name>DataCategories_Description</Name>
<Page isRef="5" />
<Parent isRef="6" />
<Text>{Categories.Description}</Text>
<TextBrush>Black</TextBrush>
<TextOptions>HotkeyPrefix=None, LineLimit=False, RightToLeft=False, Trimming=None, WordWrap=True, Angle=0, FirstTabOffset=40, DistanceBetweenTabs=20,</TextOptions>
<VertAlignment>Center</VertAlignment>
</DataCategories_Description>
</Components>
<Conditions isList="true" count="0" />
<DataSourceName>Categories</DataSourceName>
<Filters isList="true" count="0" />
<Name>DataCategories</Name>
<NewPageBefore>True</NewPageBefore>
<Page isRef="5" />
<Parent isRef="5" />
<Sort isList="true" count="0" />
</DataCategories>
<DataProducts Ref="10" type="DataBand" isKey="true">
<Brush>Transparent</Brush>
<BusinessObjectGuid isNull="true" />
<ClientRectangle>0,2,19,0.8</ClientRectangle>
<Components isList="true" count="2">
<DataProducts_ProductID Ref="11" type="Text" isKey="true">
<Brush>Transparent</Brush>
<CanGrow>True</CanGrow>
<ClientRectangle>0,0,2.8,0.8</ClientRectangle>
<Conditions isList="true" count="0" />
<Font>Arial,8</Font>
<HorAlignment>Center</HorAlignment>
<Margins>0,0,0,0</Margins>
<Name>DataProducts_ProductID</Name>
<Page isRef="5" />
<Parent isRef="10" />
<Text>{Products.ProductID}</Text>
<TextBrush>Black</TextBrush>
<TextOptions>HotkeyPrefix=None, LineLimit=False, RightToLeft=False, Trimming=None, WordWrap=True, Angle=0, FirstTabOffset=40, DistanceBetweenTabs=20,</TextOptions>
<VertAlignment>Center</VertAlignment>
</DataProducts_ProductID>
<DataProducts_ProductName Ref="12" type="Text" isKey="true">
<Brush>Transparent</Brush>
<CanGrow>True</CanGrow>
<ClientRectangle>2.8,0,16.2,0.8</ClientRectangle>
<Conditions isList="true" count="0" />
<Font>Arial,8</Font>
<Margins>0,0,0,0</Margins>
<Name>DataProducts_ProductName</Name>
<Page isRef="5" />
<Parent isRef="10" />
<Text>{Products.ProductName}</Text>
<TextBrush>Black</TextBrush>
<TextOptions>HotkeyPrefix=None, LineLimit=False, RightToLeft=False, Trimming=None, WordWrap=True, Angle=0, FirstTabOffset=40, DistanceBetweenTabs=20,</TextOptions>
<VertAlignment>Center</VertAlignment>
</DataProducts_ProductName>
</Components>
<Conditions isList="true" count="0" />
<DataRelationName>CategoriesProducts</DataRelationName>
<DataSourceName>Products</DataSourceName>
<Filters isList="true" count="0" />
<MasterComponent isRef="6" />
<Name>DataProducts</Name>
<Page isRef="5" />
<Parent isRef="5" />
<Sort isList="true" count="0" />
</DataProducts>
</Components>
<Conditions isList="true" count="0" />
<Guid>f54ce908f78c4855b4d9f0abc8f326b9</Guid>
<Margins>1,1,1,1</Margins>
<Name>Page1</Name>
<PageHeight>29.7</PageHeight>
<PageWidth>21</PageWidth>
<Report isRef="0" />
<Watermark Ref="13" type="Stimulsoft.Report.Components.StiWatermark" isKey="true">
<Font>Arial,100</Font>
<TextBrush>[50:0:0:0]</TextBrush>
</Watermark>
</Page1>
</Pages>
<PrinterSettings Ref="14" type="Stimulsoft.Report.Print.StiPrinterSettings" isKey="true" />
<ReferencedAssemblies isList="true" count="8">
<value>System.Dll</value>
<value>System.Drawing.Dll</value>
<value>System.Windows.Forms.Dll</value>
<value>System.Data.Dll</value>
<value>System.Xml.Dll</value>
<value>Stimulsoft.Controls.Dll</value>
<value>Stimulsoft.Base.Dll</value>
<value>Stimulsoft.Report.Dll</value>
</ReferencedAssemblies>
<ReportAlias>Report</ReportAlias>
<ReportChanged>10/17/2012 3:55:49 PM</ReportChanged>
<ReportCreated>4/19/2011 9:33:49 AM</ReportCreated>
<ReportDescription>Basic reports demonstration.</ReportDescription>
<ReportFile>D:\DropboxFolder\Dropbox\Work\_Report samples\Dynamical page height 1.mrt</ReportFile>
<ReportGuid>ee3572d318fe4031822ddce558c4622a</ReportGuid>
<ReportName>Report</ReportName>
<ReportUnit>Centimeters</ReportUnit>
<ReportVersion>2012.3.1401</ReportVersion>
<Script>using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using Stimulsoft.Controls;
using Stimulsoft.Base.Drawing;
using Stimulsoft.Report;
using Stimulsoft.Report.Dialogs;
using Stimulsoft.Report.Components;
namespace Reports
{
public class Report : Stimulsoft.Report.StiReport
{
public Report() {
this.InitializeComponent();
}
#region StiReport Designer generated code - do not modify
#endregion StiReport Designer generated code - do not modify
}
}
</Script>
<ScriptLanguage>CSharp</ScriptLanguage>
<Styles isList="true" count="0" />
</StiSerializer>
I use from this solution:
Step 1 - set event for end rendering of report:
StiOptions.Engine.GlobalEvents.ReportEndRender += Report_EndRender;
Step 2 - set codes to handle height of page and other elements of report:
private void Report_EndRender(object sender, EventArgs e)
{
foreach (StiPage page in report.RenderedPages)
{
double max = 0;
foreach (StiComponent comp in page.GetComponents())
{
if (comp.Bottom > max) max = comp.Bottom;
}
page.PageHeight = max + page.Margins.Top + page.Margins.Bottom;
// set height for "Panel1"
page.Components["Panel1"].Height = page.Height;
}
}
Thanks for @Isham.