DevExpress 创建EXCEL
Posted 背书包的大象
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DevExpress 创建EXCEL相关的知识,希望对你有一定的参考价值。
添加库引用:DevExpress.Data.v13.1.dll、 DevExpress.Docs.v13.1.dll、DevExpress.Office.v13.1.Core.dll、 DevExpress.Spreadsheet.v13.1.Core.dll和DevExpress.Utils.v13.1.dll。
Workbook workbook = new Workbook();
// Access the first worksheet in the workbook.
Worksheet worksheet = workbook.Worksheets[0];
// Access the "A1" cell in the worksheet.
Cell cell = worksheet.Cells["A1"];
// Specify the "A1" cell value.
cell.Value = 1;
// Fill cells with sequential numbers by using shared formulas.
worksheet.Range["A2:A10"].Formula = "=SUM(A1+1)";
worksheet.Range["B1:B10"].Formula = "=A1+2";
worksheet.Range["C1:C10"].Formula = "=A1*B1";
chartControl1.ExportToImage("aaa.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
Image image = Image.FromFile("aaa.jpg");
worksheet.Pictures.AddPicture(image,worksheet.Cells["D1"]);
worksheet.Pictures.AddPicture(image,worksheet.Cells["A10"]);
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = "导出Excel";
saveFileDialog.Filter = "Excel文件(*.xls)|*.xls";
if (saveFileDialog.ShowDialog() != DialogResult.OK) return;
try
{
workbook.SaveDocument(saveFileDialog.FileName, DocumentFormat.Xls);
}
catch (Exception vErr)
{
XtraMessageBox.Show("导出数据失败!错误源:" + vErr.Message);
}
finally
{
Cursor.Current = Cursors.Default;
}
这样的话就可以实现图文并存的EXCEL了
以上是关于DevExpress 创建EXCEL的主要内容,如果未能解决你的问题,请参考以下文章
DevExpress Winform:纯代码方式创建PopupMenu
自递归 SQL Server 数据库表创建树结构,为此创建模型,并在 Devexpress 中使用此数据
使用DevExpress Reports和PDF Viewer创建AcroForm Designer