原创|使用教程|编辑:李亚男|2019-06-12 14:17:07.403|阅读 585 次
概述:TMS Flexcel Studio for .NET v6.26可以通过编写<#[db.something] .field>来引用包含点的表。并且可以在表名或字段名中使用方括号来引用包含点的表或字段。如本文.NET Framework报表演示中高级Linq示例中所示。
# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>
TMS FlexCel Studio for.NET是一款100%托管代码的Excel文件处理引擎和.NET、Xamarin.iOS、Xamarin.Android、Xamarin.Mac环境下的Excel、PDF格式报表生成器。
【TMS Flexcel Studio for .NET v6.26全新升级 | 最新版下载】
为了方便起见,这里的大多数演示使用的数据集将作为数据源。因为在.NET 2.0中不支持Linq,如果我们使用Linq,这些演示将不适用于所有人,而且焦点在Excel模板中,而不是在数据层中。但是您可以将任何IQueryable< T >集合用作FlexCel报表中的数据源,这是我们将在此处显示的内容。
当详细信息嵌套在主服务器内的多个级别时,如何执行master-detail报表。
如何使用[square brackets]引用带点的表格。
AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("(c) 2002 - 2019 TMS Software")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("6.26.0.0")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
// Microsoft .NET Framework documentation for more information on assembly signing.
//
// Use the attributes below to control which key is used for signing.
//
// Notes:
// (*) If no key is specified, the assembly is not signed.
// (*) KeyName refers to a key that has been installed in the Crypto Service
// Provider (CSP) on your machine. KeyFile refers to a file which contains
// a key.
// (*) If the KeyFile and the KeyName values are both specified, the
// following processing occurs:
// (1) If the KeyName can be found in the CSP, that key is used.
// (2) If the KeyName does not exist and the KeyFile does exist, the key
// in the KeyFile is installed into the CSP and used.
// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
// When specifying the KeyFile, the location of the KeyFile should be
// relative to the project output directory which is
// %Project Directory%\obj\. For example, if your KeyFile is
// located in the project directory, you would specify the AssemblyKeyFile
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
// documentation for more information on this.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]Form1.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Diagnostics;
using System.Reflection;
using FlexCel.Core;
using FlexCel.XlsAdapter;
using FlexCel.Report;
using System.Collections.Generic;
using System.Linq;
namespace AdvancedLinq
{
/// /// Summary description for Form1.
/// public partial class mainForm : System.Windows.Forms.Form
{
public mainForm()
{
InitializeComponent();
}
private void button1_Click(object sender, System.EventArgs e)
{
AutoRun();
}
public void AutoRun()
{
using (FlexCelReport report = new FlexCelReport(true))
{
LoadTables(report);
string DataPath = Path.Combine(Path.Combine(Path.GetDirectoryName(Assembly.
GetExecutingAssembly().Location), ".."), "..") + Path.DirectorySeparatorChar;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
report.Run(DataPath + "Advanced Linq.template.xlsx", saveFileDialog1.FileName);
if (MessageBox.Show("Do you want to open the generated file?", "Confirm",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
Process.Start(saveFileDialog1.FileName);
}
}
}
}
private void LoadTables(FlexCelReport report)
{
var Countries = new List();
Countries.Add(new Country("China",
new People(1384688986),
new Geography(
new Area(270550, 9326410))));
var country = Countries[Countries.Count - 1];
country.People.Language.Add(new Language(
new LanguageName("Md", "Mandarin"),
new LanguageSpeakers(0, 66.2)));
country.People.Language.Add(new Language(
new LanguageName("Yue", "Yue"),
new LanguageSpeakers(0, 4.9)));
country.People.Language.Add(new Language(
new LanguageName("Wu", "Wu"),
new LanguageSpeakers(0, 6.1)));
country.People.Language.Add(new Language(
new LanguageName("Mb", "Minbei"),
new LanguageSpeakers(0, 6.2)));
country.People.Language.Add(new Language(
new LanguageName("Mn", "Minnan"),
new LanguageSpeakers(0, 5.2)));
country.People.Language.Add(new Language(
new LanguageName("Xi", "Xiang"),
new LanguageSpeakers(0, 3.0)));
country.People.Language.Add(new Language(
new LanguageName("Gan", "Gan"),
new LanguageSpeakers(0, 4.0)));
Countries.Add(new Country("India",
new People(1296834042),
new Geography(
new Area(314070, 2973193))));
country = Countries[Countries.Count - 1];
country.People.Language.Add(new Language(
new LanguageName("Hi", "Hindi"),
new LanguageSpeakers(0, 43.6)));
country.People.Language.Add(new Language(
new LanguageName("Bg", "Bengali"),
new LanguageSpeakers(0, 8)));
country.People.Language.Add(new Language(
new LanguageName("Ma", "Marath"),
new LanguageSpeakers(0, 6.9)));
country.People.Language.Add(new Language(
new LanguageName("Te", "Telugu"),
new LanguageSpeakers(0, 6.7)));
country.People.Language.Add(new Language(
new LanguageName("Ta", "Tamil"),
new LanguageSpeakers(0, 5.7)));
country.People.Language.Add(new Language(
new LanguageName("Gu", "Gujarati"),
new LanguageSpeakers(0, 4.6)));
country.People.Language.Add(new Language(
new LanguageName("Ur", "Urdu"),
new LanguageSpeakers(0, 4.2)));
country.People.Language.Add(new Language(
new LanguageName("Ka", "Kannada"),
new LanguageSpeakers(0, 3.6)));
country.People.Language.Add(new Language(
new LanguageName("Od", "Odia"),
new LanguageSpeakers(0, 3.1)));
country.People.Language.Add(new Language(
new LanguageName("Ma", "Malayalam"),
new LanguageSpeakers(0, 2.9)));
country.People.Language.Add(new Language(
new LanguageName("Pu", "Punjabi"),
new LanguageSpeakers(0, 2.7)));
country.People.Language.Add(new Language(
new LanguageName("As", "Assamese"),
new LanguageSpeakers(0, 1.3)));
country.People.Language.Add(new Language(
new LanguageName("Mi", "Maithili"),
new LanguageSpeakers(0, 1.1)));
country.People.Language.Add(new Language(
new LanguageName("O", "Other"),
new LanguageSpeakers(0, 5.6)));
Countries.Add(new Country("United States",
new People(329256465),
new Geography(
new Area(685924, 9147593))));
country = Countries[Countries.Count - 1];
country.People.Language.Add(new Language(
new LanguageName("En", "English"),
new LanguageSpeakers(0, 78.2)));
country.People.Language.Add(new Language(
new LanguageName("Sp", "Spanish"),
new LanguageSpeakers(0, 13.4)));
country.People.Language.Add(new Language(
new LanguageName("Ch", "Chinese"),
new LanguageSpeakers(0, 1.1)));
country.People.Language.Add(new Language(
new LanguageName("O", "Other"),
new LanguageSpeakers(0, 7.3)));
report.AddTable("country", Countries );
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
Close();
}
}
public class Country
{
public string Name { get; private set; }
public People People { get; set; }
public Geography Geography { get; set; }
public Country(string name, People people, Geography geography)
{
this.Name = name;
this.People = people;
this.Geography = geography;
}
}
public class Geography
{
public Area Area { get; private set; }
public Geography(Area area)
{
this.Area = area;
}
}
public class Area
{
public int Total { get { return Water + Land; } }
public int Water { get; private set; }
public int Land { get; private set; }
public Area(int water, int land)
{
this.Water = water;
this.Land = land;
}
}
public class People
{
public int Population { get; private set; }
public List Language { get; private set; }
public People(int population)
{
this.Population = population;
this.Language = new List();
}
}
public class Language
{
public LanguageName Name { get; private set; }
public LanguageSpeakers Speakers { get; private set; }
public Language(LanguageName name, LanguageSpeakers speakers)
{
this.Name = name;
this.Speakers = speakers;
}
}
public class LanguageName
{
public string ShortName { get; private set; }
public string LongName { get; private set; }
public LanguageName(string shortName, string longName)
{
this.ShortName = shortName;
this.LongName = longName;
}
}
public class LanguageSpeakers
{
public int AbsoluteNumber { get; private set; }
public double Percent { get; private set; }
public LanguageSpeakers(int absoluteNumber, double percent)
{
this.AbsoluteNumber = absoluteNumber;
this.Percent = percent / 100.0;
}
}
}Form1.Designer.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Diagnostics;
using System.Reflection;
using FlexCel.Core;
using FlexCel.XlsAdapter;
using FlexCel.Report;
namespace AdvancedLinq
{
public partial class mainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnCancel;
/// /// Required designer variable.
/// private System.ComponentModel.Container components = null;
/// /// Clean up any resources being used.
/// protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// /// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.label1 = new System.Windows.Forms.Label();
this.btnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.
AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button1.BackColor = System.Drawing.Color.Green;
this.button1.ForeColor = System.Drawing.Color.White;
this.button1.Location = new System.Drawing.Point(152, 88);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(112, 23);
this.button1.TabIndex = 0;
this.button1.Text = "GO!";
this.button1.UseVisualStyleBackColor = false;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// saveFileDialog1
//
this.saveFileDialog1.Filter = "Excel Files|*.xlsx";
this.saveFileDialog1.RestoreDirectory = true;
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(272, 24);
this.label1.TabIndex = 2;
this.label1.Text = "Press \"GO\" to create a report from a List<> of objects.";
//
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.
Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))),
((int)(((byte)(0)))), ((int)(((byte)(0)))));
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.ForeColor = System.Drawing.Color.White;
this.btnCancel.Location = new System.Drawing.Point(272, 88);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(112, 23);
this.btnCancel.TabIndex = 3;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = false;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// mainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(416, 133);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.label1);
this.Controls.Add(this.button1);
this.Name = "mainForm";
this.Text = "Advanced Linq Reports";
this.ResumeLayout(false);
}
#endregion
}
}Program.cs
using System;
using System.Windows.Forms;
namespace AdvancedLinq
{
static class Program
{
/// /// The main entry point for the application.
/// [STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new mainForm());
}
}
}【注:本演示需要.NET 3.5或更新版本。】
购买TMS Flexcel Studio for .NET v6.26正版授权的朋友可以点击""哦~~~
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@ke049m.cn