C# WinfForm 控件之dev电子表格 SpreadSheet
网上找了一些资料可是不得入门 只能再回过头来看demos
看了一点 例子大多继承自SpreadsheetRibbonTutorialControlBase 这个类,它又继承自SpreadSheetTutorialControlBase 再往前就不说了
SpreadSheetTutorialControlBase 这个类呢 只是定义了两个属性 可能就是运行语言格式的 没有注释
SpreadsheetRibbonTutorialControlBase 这个呢又定义了一个属性 selectPage 看样是选中的按钮页的意思,类型是 RibbonPage 又绑定了两个方法 一个是单元格值改变 另一个呢是 是最后编辑,我想是这样的 看名字 (spreadsheetControl1_CellValueChangedOverride、spreadsheetControl1_CellEndEditOverride)这个类就有所有的控件了,这是他的样子。有个doShow()(大约是显示的意思)方法 这个应继承自最基类的dll里先不管什么意思
再看他的子类们
1.AutoFilterModule 打开一个文档 看注释
namespace DevExpress.XtraSpreadsheet.Demos {
public partial class AutoFilterModule : SpreadsheetRibbonTutorialControlBase {
public AutoFilterModule() {
InitializeComponent(); // 这个是en-US 。。。英语的 (汉化的话 在程序入口加 en-Hans 这去百度用法)
spreadsheetControl1.Options.Culture = DefaultCulture; //这个打开路径下的 auto...xlsx表格 getRelativePath是取程序路径 可以看到spreadsheetControl1.LoadDocument就是把文档加到spreadSheetControl中
spreadsheetControl1.LoadDocument(DemoUtils.GetRelativePath("AutoFilter_template.xlsx"));
} #region Properties 重载了 选中dataribbonPage1
protected internal override RibbonPage SelectedRibbonPage { get { return dataRibbonPage1; } }
#endregion
}
}
2。 BreakevenAnalysisModule 定义一个workBook 接收 ssc.document ssc是spreadSheetControl下同 并加载excel表格 这个有点错误 ssc.docment 是取ssc上的sheet的意思
namespace DevExpress.XtraSpreadsheet.Demos {
public partial class BreakevenAnalysisModule : SpreadsheetRibbonTutorialControlBase {
public BreakevenAnalysisModule() {
InitializeComponent();
InitializeWorkbook();
} #region Properties
protected internal override RibbonPage SelectedRibbonPage { get { return insertRibbonPage1; } }
#endregion //新建一个空文档 并加入excel表格 IWorkbook=spreadsheetControl1.Document;
void InitializeWorkbook() {
IWorkbook workbook = spreadsheetControl1.Document;
workbook.LoadDocument(DemoUtils.GetRelativePath("BreakevenAnalysis.xlsx"));
}
}
}
3.CellPropertiesViewerModule
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using DevExpress.DXperience.Demos;
using DevExpress.XtraVerticalGrid.Rows;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraVerticalGrid;
using DevExpress.XtraVerticalGrid.Events;
using DevExpress.Spreadsheet;
using System.Diagnostics; namespace DevExpress.XtraSpreadsheet.Demos {
public partial class CellPropertiesViewerModule : SpreadsheetRibbonTutorialControlBase {
IWorkbook workbook;
Worksheet sheet;
Range selectedCell; public CellPropertiesViewerModule() {
InitializeComponent();
InitializePropertyGrid();
InitializeWorkbook(); //清空历史文档 spreadsheetControl1.Document.History.Clear()
this.spreadsheetControl1.Document.History.Clear();
} /// <summary>
/// 绑定 两个事件
/// </summary>
protected internal override void SubscribeEvents() {
base.SubscribeEvents();
spreadsheetControl1.ContentChanged += spreadsheetControl1_ContentChanged;
spreadsheetControl1.SelectionChanged += spreadsheetControl1_SelectionChanged;
} //单元格改变是显示单元格属性
void spreadsheetControl1_ContentChanged(object sender, EventArgs e) {
workbook = spreadsheetControl1.Document;
sheet = workbook.Worksheets.ActiveWorksheet;//活动页
selectedCell = sheet.SelectedCell; //选中的单元格
propertyGridControl1.SelectedObject = new RangeAdapter(selectedCell);//选中表格的属性 类在下边;
} /// <summary>
/// 不同步的话就同步过来
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void spreadsheetControl1_SelectionChanged(object sender, EventArgs e) {
workbook = spreadsheetControl1.Document;
sheet = workbook.Worksheets.ActiveWorksheet;
if (!sheet.SelectedCell.Equals(selectedCell)) {
selectedCell = sheet.SelectedCell;
propertyGridControl1.SelectedObject = new RangeAdapter(selectedCell);
}
} #region PropertyGrid initialization 初始化属性表格
void InitializePropertyGrid() {
CategoryRow contentCategory = AddCategoryRow(null, "CellContent", "Cell content");//一级 cellContent
AddEditorRow(contentCategory, "Cell.Formula", "Formula"); // cellcontent的下一级
AddEditorRow(contentCategory, "Cell.ArrayFormula", "ArrayFormula"); CategoryRow valueCategory = AddCategoryRow(contentCategory, "Value", "Value");
AddEditorRow(valueCategory, "Value.TextValue", "TextValue");
AddEditorRow(valueCategory, "Value.BooleanValue", "BooleanValue");
AddEditorRow(valueCategory, "Value.NumericValue", "NumericValue");
AddEditorRow(valueCategory, "Value.ErrorValue", "ErrorValue");
AddEditorRow(valueCategory, "Value.Type", "Type"); CategoryRow formattingCategory = AddCategoryRow(null, "Formatting", "Formatting"); CategoryRow numberFormatCategory = AddCategoryRow(formattingCategory, "NumberFormat", "NumberFormat");
AddEditorRow(numberFormatCategory, "NumberFormat", "NumberFormat");
AddEditorRow(numberFormatCategory, "Cell.IsDisplayedAsDateTime", "IsDisplayedAsDateTime"); CategoryRow alignmentCategory = AddCategoryRow(formattingCategory, "Alignment", "Alignment");
AddEditorRow(alignmentCategory, "Alignment.Horizontal", "Horizontal");
AddEditorRow(alignmentCategory, "Alignment.Vertical", "Vertical");
AddEditorRow(alignmentCategory, "Alignment.Indent", "Indent");
AddEditorRow(alignmentCategory, "Alignment.WrapText", "WrapText"); CategoryRow fillCategory = AddCategoryRow(formattingCategory, "Fill", "Fill");
AddEditorRow(fillCategory, "Fill.BackgroundColor", "Color"); CategoryRow fontCategory = AddCategoryRow(formattingCategory, "Font", "Font");
AddEditorRow(fontCategory, "Font.Color", "Color");
AddEditorRow(fontCategory, "Font.Name", "Name");
AddEditorRow(fontCategory, "Font.FontStyle", "FontStyle");
AddEditorRow(fontCategory, "Font.Script", "Script");
AddEditorRow(fontCategory, "Font.Size", "Size");
AddEditorRow(fontCategory, "Font.Strikethrough", "Strikethrough");
AddEditorRow(fontCategory, "Font.UnderlineType", "UnderlineType"); CategoryRow bordersCategory = AddCategoryRow(formattingCategory, "Borders", "Borders");
CategoryRow diagBorderCategory = AddCategoryRow(bordersCategory, "DiagonalBorder", "Diagonal");
AddEditorRow(diagBorderCategory, "Borders.DiagonalBorderColor", "Color");
AddEditorRow(diagBorderCategory, "Borders.DiagonalBorderLineStyle", "LineStyle");
AddEditorRow(diagBorderCategory, "Borders.DiagonalBorderType", "Type"); CategoryRow leftBorderCategory = AddCategoryRow(bordersCategory, "LeftBorder", "Left");
AddEditorRow(leftBorderCategory, "LeftBorder.Color", "Color");
AddEditorRow(leftBorderCategory, "LeftBorder.LineStyle", "LineStyle"); CategoryRow topBorderCategory = AddCategoryRow(bordersCategory, "TopBorder", "Top");
AddEditorRow(topBorderCategory, "TopBorder.Color", "Color");
AddEditorRow(topBorderCategory, "TopBorder.LineStyle", "LineStyle"); CategoryRow rightBorderCategory = AddCategoryRow(bordersCategory, "RightBorder", "Right");
AddEditorRow(rightBorderCategory, "RightBorder.Color", "Color");
AddEditorRow(rightBorderCategory, "RightBorder.LineStyle", "LineStyle"); CategoryRow bottomBorderCategory = AddCategoryRow(bordersCategory, "BottomBorder", "Bottom");
AddEditorRow(bottomBorderCategory, "BottomBorder.Color", "Color");
AddEditorRow(bottomBorderCategory, "BottomBorder.LineStyle", "LineStyle"); CategoryRow styleCategory = AddCategoryRow(formattingCategory, "Style", "Style");
AddEditorRow(styleCategory, "Style.Name", "Name"); CategoryRow layoutCategory = AddCategoryRow(null, "Layout", "Layout");
AddEditorRow(layoutCategory, "Cell.ColumnWidth", "Width");
AddEditorRow(layoutCategory, "Cell.ColumnWidthInCharacters", "WidthInCharacters");
AddEditorRow(layoutCategory, "Cell.RowHeight", "Height"); CategoryRow protectionCategory = AddCategoryRow(null, "Protection", "Protection");
AddEditorRow(protectionCategory, "Protection.Locked", "Locked"); bordersCategory.Expanded = false;
} CategoryRow AddCategoryRow(CategoryRow parent, string name, string caption) {
CategoryRow result = new CategoryRow(name);
result.Properties.Caption = caption;
if (parent == null)
propertyGridControl1.Rows.Add(result);
else
parent.ChildRows.Add(result);
return result;
}
void AddEditorRow(CategoryRow parent, string name, string caption) {
EditorRow row = new EditorRow(name);
row.Properties.Caption = caption;
parent.ChildRows.Add(row);
}
#endregion #region Sample workbook initialization
void InitializeWorkbook() {
workbook = spreadsheetControl1.Document;
workbook.LoadDocument(DemoUtils.GetRelativePath("CellPropertiesViewer_template.xlsx"));
}
#endregion protected override void DoShow() {
base.DoShow();
spreadsheetControl1.Focus();//焦点
}
} //属性对应的类
public class RangeAdapter {
Range range; public RangeAdapter(Range range) {
this.range = range;
} public Cell Cell { get { return range.Worksheet.Cells[range.TopRowIndex, range.LeftColumnIndex]; } }
public CellValue Value { get { return range.Value; } }
public Alignment Alignment { get { return range.Alignment; } }
public Borders Borders { get { return range.Borders; } }
public Border LeftBorder { get { return range.Borders.LeftBorder; } }
public Border TopBorder { get { return range.Borders.TopBorder; } }
public Border RightBorder { get { return range.Borders.RightBorder; } }
public Border BottomBorder { get { return range.Borders.BottomBorder; } }
public Fill Fill { get { return range.Fill; } }
public DevExpress.Spreadsheet.SpreadsheetFont Font { get { return range.Font; } }
public Protection Protection { get { return range.Protection; } }
public Style Style { get { return range.Style; } }
public string NumberFormat { get { return Cell.NumberFormat; } set { Cell.NumberFormat = value; } }
}
}
4.ChartApiMode 这个 显示c#与VB的demo 后能不管他了 看他前台的demo 这里只看一个
private void button1_Click(object sender, EventArgs e)
{
IWorkbook workbook = ssc.Document;
Worksheet worksheet = workbook.Worksheets["sheet2"]; worksheet.Cells["B2"].Value = "Phone";
worksheet.Cells["c2"].Value = "pecent";
worksheet.Cells["B4"].Value="adriod";
worksheet.Cells["c4"].Value = ;
worksheet.Cells["b3"].Value = "iso";
worksheet.Cells["c3"].Value = ;
workbook.Worksheets.ActiveWorksheet = worksheet; // 建一个本地图. 取值区间如果有无效数据则忽略
DevExpress.Spreadsheet.Charts.Chart chart = worksheet.Charts.Add(ChartType.PieExploded, worksheet["B3:C4"]); //图表位置
chart.TopLeftCell = worksheet.Cells["E2"];
chart.BottomRightCell = worksheet.Cells["K15"]; // 颜色类型.
chart.Style = ChartStyle.ColorArea; // 隐藏右侧的说明
chart.Legend.Visible = false; // 第一个切片的角度 .
chart.Views[].FirstSliceAngle = ; // 各个切片是否显示名称 百分比 及显示方式为换行.
DataLabelOptions dataLabels = chart.Views[].DataLabels;
dataLabels.ShowCategoryName = true;
dataLabels.ShowPercent = true;
dataLabels.Separator = "\n"; }
5.ConditionalFormatting 这个主要是改变背景色 等显示 代码实现在TopTradingPartners这个静态类里 只看一个例子
public static void ApplyTopImportsConditionalFormatting(Worksheet sheet) {
ConditionalFormattingCollection conditionalFormattings = sheet.ConditionalFormattings;
// 建一个 imports 列 5个格改变颜色.
RankConditionalFormatting cfRule2 = conditionalFormattings.AddRankConditionalFormatting(sheet["Table[Imports]"], ConditionalFormattingRankCondition.TopByRank, );
// Specify formatting options to be applied to cells if the condition is true.
// Set the background color to light-red.
cfRule2.Formatting.Fill.BackgroundColor = Color.FromArgb(0xFC, 0xB3, 0xB3);
}
6.删除空列(空行同 只不过是遍历行操作)
for (int i = spreadsheetControl1.ActiveWorksheet.Columns.LastUsedIndex; i >= ; i--)
{
bool b = false;
for (int j = spreadsheetControl1.ActiveWorksheet.Rows.LastUsedIndex; j >= ; j--)
{
if (spreadsheetControl1.ActiveWorksheet.Rows[j][i].Value.ToString() != "")
{
b = true;
break;
} } if (!b)
{
spreadsheetControl1.ActiveWorksheet.Columns.Remove(i); }
}
7.取消所有的合并单元格
foreach (var item in spreadsheetControl1.ActiveWorksheet.Cells.GetMergedRanges())
{
item.UnMerge();
}
C# WinfForm 控件之dev电子表格 SpreadSheet的更多相关文章
- C# WinfForm 控件之dev图表 ChartControl
dev 图表控件 学习连接 新建一个winformApp form1上放一个button 再放一个chartControl Name 为cct 直接上代码 private void button1_C ...
- C# WinfForm 控件之dev报表 XtraReport (八)动态生成报表
功能说明:生成一个报表文件DV1,保存到本地AA.rep,再重新加载这个文件到DV2 1.布局如下图: panel1 上有三个button panel2上有个documentView dv1 pane ...
- C# WinfForm 控件之dev报表 XtraReport (四) 动态绑定主从关系表
一般的单据都是由主从关系的,比如部门与人员.单据表头与表身.仓库与存货.分类与档案等等 所以主从关系是报表用的最多的 1.准备数据库 简单方便 --主表 create table RdRecord ( ...
- C# WinfForm 控件之dev报表 XtraReport(三) 动态数据绑定
代码还用上一节的,把reportFrx的dataSource去掉.各cell绑定的字段也去掉,有了第二节的基础,现在看这个ms就不难了 无非就是 传到reportFrx一个数据集 在把这个数据集 绑到 ...
- C# WinfForm 控件之dev报表 XtraReport (二) 固定数据绑定
已经子解了XtraReport的初步用法 现在再进一步了解 数据绑定 我们还是先不整高深的 先来个写死的 让我们的数据库数据可以通过报表呈现先 1.准备 还在上节基础上 只不过我把form1 中的Do ...
- C# WinfForm 控件之dev报表 XtraReport (一) 初了解
这个控件其实用法和fast也差不了太多但如果没接触过 真有种老虎吃天的感觉 1.这里先不说那些高深的先说最基本的 在窗体中显示一个设计好的 模版 1.1一般设计和这个程序是分着的为了方便我就先把他们合 ...
- C# WinfForm 控件之dev报表 XtraReport (七)报表合并
这个不是太难,新建两个报表 一个form窗体 窗体上放个documentView 代码如下 XtraReport2 xr2 = new XtraReport2(); xr2.CreateDocume ...
- C# WinfForm 控件之dev表格 GridControl
基本用法 1.新建一个winformAPP 放一个gridControl 为gridC 再放一个button 用法与dataGrid一样 代码如下: /// <summary> /// 显 ...
- C# WinfForm 控件之dev报表 XtraReport (五) 并排报表
有了前边的基础这个就很简单了,建一个容器报表 在detail,上放两个xrsubReport.再做两个明细报表,分别指定到xrsubreport就可以了
随机推荐
- Java + selenium 启动谷歌浏览器
在之前创建的test项目下建一个test包,然后在包下建一个Chrome.java类.写入如下代码 package test; import java.util.concurrent.TimeUnit ...
- PAT甲级——A1151 LCA_in_a_BinaryTree【30】
The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U ...
- Linux(四)—— 项目部署与ansible自动化部署
目录 项目部署与ansible自动化部署 一.项目部署 二.ansible自动化部署(python自动化运维) 1.安装ansible 2.ansible例子 3.ansible自动化部署nginx ...
- Spark on YARN--WordCount、TopK
原文地址:http://blog.csdn.net/cklsoft/article/details/25568621 1.首先利用http://dongxicheng.org/framework-on ...
- 深入Linux内核架构 - 内核之中数据结构之间的关系图 & 设备驱动程序(转)
内核之中数据结构之间的关系图 设备驱动程序
- python tkinter 实现 带界面(GUI)的RSA加密、签名
代码环境,python3.5.2 RSA加密的过程是:使用公钥加密,私钥解密 RSA签名的过程是:使用私钥签名,公钥验证 所以核心代码就是,生成公钥私钥,使用公钥私钥分别进行加密解密. 在实际编码的时 ...
- MyBatis笔记二:配置
MyBatis笔记二:配置 1.全局配置 1.properites 这个配置主要是引入我们的 properites 配置文件的: <properties resource="db.pr ...
- js异步处理
一.什么是异步? 我们一般喜欢把异步和同步.并行拿出来比较,我以前的理解总是很模糊,总是生硬地记着“同步就是排队执行,异步就是一起执行”,现在一看,当初简直就是傻,所以我们第一步先把这三个概念搞清楚, ...
- Vue开发环境安装并集成element-ui示例
此文为转载,原文链接:https://blog.csdn.net/weixin_44670973/article/details/88871106 在此对原文中部分内容进行补充. 补充:element ...
- KiCAD原理图导出PDF方法
KiCAD原理图导出为PDF 1.文件->绘制 2.按照下图选择保存目录和输出格式后,选择绘制当前页或者所有页