繁体   English   中英

如何在WPF上使用选定项制作Excel文件

[英]How to make Excel file with Selected Items on WPF

我正在尝试将日志文件另存为Excel。

我有EventInfo.cs文件:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class EventLogInfo
{
    public string Id { get; set; }     
    public string Camera { get; set; } 
    public string Device { get; set; }
    public Int16 Region { get; set; }
    public Int16 Event { get; set; }

有ID,相机,设备,区域,事件项。

我使用“ 如何从Microsoft Visual C#.NET KB 自动化Microsoft Excel”文章,可以这样:

using System;
using System.Reflection;

namespace ExcelOutput  

public partial class ExcelOutput : Window
    {
        public ExcelOutput()
        {
            InitializeComponent();
        }


        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
          try
            {
                //Start Excel and get Application object.
                //oXL = new Excel.Application();
                //oXL.Visible = false;
                //oXL.UserControl = false;
                //oXL.DisplayAlerts = false;

                oSheet.Cells[1, 1] = "Id";
                oSheet.Cells[1, 2] = "Camera";
                oSheet.Cells[1, 3] = "Device";
                oSheet.Cells[1, 4] = "Region";
                oSheet.Cells[1, 5] = "Event";

当我单击Excel输出按钮时,将创建Excel文件。 但是我想选择一些项目(ID,摄像机,设备,区域,事件)并另存为Excel。

选择项目的最佳方法是什么,如何使Excel文件对选择的项目进行排序?

创建完Excel文件后,只需将数据放在相应的单元格中即可。

if (InitializeExcel())
{
dynamic cell;
cell = oSheet.Cells[1, 1]; cell.Value = Id;
cell = oSheet.Cells[1, 2]; cell.Value = Camera;
.
.
.
}

等等..

我会推荐Open XML SDK。 这样,您可以创建Excel文件而无需安装Excel。 它也更快。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM