C1XLBook wb = new C1XLBook(); wb.CompatibilityMode = C1.C1Excel.CompatibilityMode.Excel2007;
XLSheet ws1 = null;
XLSheet ws2 = null;
wb.Clear();
XLSheet wsA1 = wb.Sheets[0];
XLSheet wsA2 = wb.Sheets[1];
wb.Sheets[0].Name = "外机";
wb.Sheets[1].Name = "内机";
wsA1[1, 0].Value = "时间";
wsA1[1, 301].Value = "容量";
wsA1[1, 302].Value = "总和";
//外机1
XLCellRange _Rowsys = new C1.C1Excel.XLCellRange(0, 0, 1, 59);
//外机2
XLCellRange _RowRange1 = new C1.C1Excel.XLCellRange(0, 0, 60, 118);
//外机3
XLCellRange _RowRange2 = new C1.C1Excel.XLCellRange(0, 0, 119, 177);
//外机4
XLCellRange _RowRange3 = new C1.C1Excel.XLCellRange(0, 0, 178, 236);
//系统参数
XLCellRange _RowRange4 = new C1.C1Excel.XLCellRange(0, 0, 237, 300);
//Merge Cells
wsA1.MergedCells.Add(_Rowsys);
wsA1.MergedCells.Add(_RowRange1);
wsA1.MergedCells.Add(_RowRange2);
wsA1.MergedCells.Add(_RowRange3);
wsA1.MergedCells.Add(_RowRange4);
//定义合并单元格样式
XLStyle _Colstyle = new C1.C1Excel.XLStyle(wb);
_Colstyle.AlignHorz = XLAlignHorzEnum.Center;
_Colstyle.SetBorderStyle(XLLineStyleEnum.Medium);
_Colstyle.SetBorderColor(Color.DarkBlue);
_Colstyle.Font = new System.Drawing.Font("微软雅黑", 14.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
_Rowsys.Style = _Colstyle;
_RowRange1.Style = _Colstyle;
_RowRange2.Style = _Colstyle;
_RowRange3.Style = _Colstyle;
_RowRange4.Style = _Colstyle;
wsA1[0, 1].Value = "主机";
wsA1[0, 60].Value = "从2";
wsA1[0, 119].Value = "从3";
wsA1[0, 178].Value = "从4";
wsA1[0, 237].Value = "系统";
for (int i = 237; i < 301; i++)
{
wsA1[1, i].Value = (i - 236) + "线状态";
}
wsA2[1, 0].Value = "时间";
XLCellRange xlcel;
for (int i = 0; i < 64; i++)
{
wsA2[1, i * 26 + 1].Value = "内" + (i + 1) + "温度1";
wsA2[1, i * 26 + 2].Value = "内" + (i + 1) + "温度2";
wsA2[1, i * 26 + 3].Value = "内" + (i + 1) + "温度3";
wsA2[1, i * 26 + 4].Value = "内" + (i + 1) + "温度4";
wsA2[1, i * 26 + 5].Value = "内" + (i + 1) + "容量";
}
//系统参数
wsA2[0, i * 26 + 1].Value = (i + 1) + "内机";
xlcel = new C1.C1Excel.XLCellRange(0, 0, i * 26 + 1, i * 26+ 26);
wsA2.MergedCells.Add(xlcel);
xlcel.Style = _Colstyle;
wb.Save(cpath);
while (true)
{//实时读取
try
{
wb.Load(cpath);
ws1= wb.Sheets[0];
row = ws1.Rows.Count;
ws1[row, 0].Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
ws1[row, 301].Value ="实时值";
ws1[row, 302].Value ="实时值";
ws2[row2, i * ncount + 1].Value =“实时值”;
ws2[row2, i * ncount + 1].Value =“实时值”;
wb.Save(cpath);
//这里。由于数据多。所以 这里就没有做 延时。
}
catch (Exception ex)
{
mt.Write("错误:"+ex.Message.ToString());
}
}
|