龙空技术网

「XtraReport报表」单元格合并

java笔记 303

前言:

现时朋友们对“java合并单元格”可能比较珍视,朋友们都想要剖析一些“java合并单元格”的相关内容。那么小编在网摘上收集了一些对于“java合并单元格””的相关内容,希望大家能喜欢,看官们快快来了解一下吧!

使用场景

今天接到需求说,要把报表同一列值相同的做合并,效果如下图2。由于对XtraReport不熟悉,了解官网后,终于找到答案。怎么用?官网还提供了demo代码。

效果图

图1.原来的样子

图2.合并单元格后的样子

关键代码

 tc1.ProcessDuplicatesMode = ProcessDuplicatesMode.Merge; tc1.ProcessDuplicatesTarget = ProcessDuplicatesTarget.Value;
完整代码
using System;using System.Drawing;using System.Collections;using System.ComponentModel;using DevExpress.XtraReports.UI;using System.Collections.Generic;namespace WPFXtraReportMergeCells{    public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport    {        public XtraReport1()        {            InitializeComponent();            InsertDataIntoTable();        }        private void InsertDataIntoTable()        {            List<Car> _cars = Car.getCars();            this.DataSource = _cars;            xrTable1.BeginInit();            xrTable1.Borders = DevExpress.XtraPrinting.BorderSide.All;            Single col1width = 216.67F;            Single col2width = 216.67F;            Single col3width = 216.67F;            xrTableCell1.WidthF = col1width;            xrTableCell1.Text = "Brand";            xrTableCell2.WidthF = col2width;            xrTableCell2.Text = "Model";            xrTableCell3.WidthF = col3width;            xrTableCell3.Text = "Reg. no.";            xrTable1.EndInit();            XRTable table = new XRTable();            table.Borders = DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Bottom | DevExpress.XtraPrinting.BorderSide.Right;            Detail.Controls.Add(table);            table.BeginInit();            XRTableRow tr = new XRTableRow();            XRTableCell tc1 = new XRTableCell();            tc1.WidthF = col1width;            tc1.ProcessDuplicatesMode = ProcessDuplicatesMode.Merge;            tc1.ProcessDuplicatesTarget = ProcessDuplicatesTarget.Value;            tc1.DataBindings.Add(new XRBinding("Text", _cars, "Brand"));            tr.Cells.Add(tc1);            XRTableCell tc2 = new XRTableCell();            tc2.WidthF = col2width;            tc2.DataBindings.Add(new XRBinding("Text", _cars, "Model"));            tr.Cells.Add(tc2);            XRTableCell tc3 = new XRTableCell();            tc3.WidthF = col3width;            tc3.DataBindings.Add(new XRBinding("Text", _cars, "Regno"));            tr.Cells.Add(tc3);            table.Rows.Add(tr);            table.AdjustSize();            table.EndInit();        }        public class Car        {            public int Id { get; set; }            public string Brand { get; set; }            public string Model  { get; set; }            public string Regno { get; set; }            public static List<Car> getCars()            {                List<Car> list = new List<Car>();                list.Add(new Car { Id = 1, Brand = "Ford", Model = "Fiesta", Regno = "XZ 11 123" });                list.Add(new Car { Id = 2, Brand = "Ford", Model = "Focus", Regno = "XZ 11 124" });                list.Add(new Car { Id = 3, Brand = "Ford", Model = "Mondeo", Regno = "XZ 11 125" });                list.Add(new Car { Id = 4, Brand = "VW", Model = "UP", Regno = "XZ 11 126" });                list.Add(new Car { Id = 5, Brand = "VW", Model = "Polo", Regno = "XZ 11 127" });                list.Add(new Car { Id = 6, Brand = "VW", Model = "Golf", Regno = "XZ 11 128" });                list.Add(new Car { Id = 7, Brand = "VW", Model = "Passat", Regno = "XZ 11 129" });                list.Add(new Car { Id = 8, Brand = "Toyota", Model = "Aygo", Regno = "XZ 11 130" });                list.Add(new Car { Id = 9, Brand = "Toyota", Model = "Yaris", Regno = "XZ 11 131" });                list.Add(new Car { Id = 10, Brand = "Toyota", Model = "Avensis", Regno = "XZ 11 132" });                return list;            }        }    }}

官网

标签: #java合并单元格 #java合并单元格行