ReoGrid一个支持excel操作的控件,支持集成到任何winfrom项目内。
先看效果图:
如何使用:
使用ReoGrid自带excel模版设计工具先设计一个模版,设计器如下:
具体例子看官方文档
代码示例如下:
var sheet = reoGridControl1.CurrentWorksheet;
SetReadOnly(sheet, new RangePosition("A1:AB2"));//设置只读
sheet.Ranges[sheet.Rows - num, 0, sheet.Rows, 24].BorderOutside = RangeBorderStyle.BlackBoldSolid;
sheet.Ranges[sheet.Rows - num, 0, sheet.Rows, 24].BorderInsideHorizontal = RangeBorderStyle.BlackSolid;
sheet.Ranges[sheet.Rows - num, 0, sheet.Rows, 24].BorderInsideVertical = RangeBorderStyle.BlackDotted;
增加边框
private void Sheet_CellDataChanged(object sender, unvell.ReoGrid.Events.CellEventArgs e)
{
var sheet = reoGridControl1.CurrentWorksheet;
int iid = Tools.ToInt(sheet.Cells[e.Cell.Row, iidNum].Data, 0);
string state = sheet.Cells[e.Cell.Row, stateNum].Data + "";
if (iid < 1 && string.IsNullOrEmpty(state))
{
sheet[e.Cell.Row, stateNum] = "Add";
}
else if (iid > 0 && string.IsNullOrEmpty(state))
{
sheet[e.Cell.Row, stateNum] = "Update";
}
}
public bool SetReadOnly(Worksheet sheet, RangePosition range)
{
sheet.IterateCells(range, ((row, col, cell) =>
{
cell.IsReadOnly = true;
return true;
}));
return true;
}
private void ReLoadGrid()
{
using (var ms = new System.IO.MemoryStream(Ufida.U8.Portal.ReportList.Properties.Resources.demo6))
{
reoGridControl1.Load(ms, unvell.ReoGrid.IO.FileFormat.ReoGridFormat);
var sheet1 = reoGridControl1.CurrentWorksheet;
sheet1.AfterCellEdit -= Sheet_CellDataChanged;
sheet1.AfterCellEdit += Sheet_CellDataChanged;
SetReadOnly(sheet1, new RangePosition("A1:AB2"));
}
}
加载模版