C# DevExpress spreadsheetControl的基本使用方法 Excel插件

时间:2025-04-18 08:15:35
 //打开Excel
        private void barButtonItem1_ItemClick(object sender,  e)
        {
            if (Convert.ToInt32(trv_menu.) == 0)
            {
                ("请先选择业务", "提示信息", );
                return;
            }
             = "*.xls|*.xlsx";
             = true;
            if (() == )
            { 
                ();
            }
             = false;
            //barButtonItem_Save.Visibility =. ;
            barButtonItem_Save.Enabled = true;
        }
//读取Excele方法
  //当前数据行数
            int rowCount = ;
            //当前数据列数
            int columnCount = ;
            if (rowCount == 1 && columnCount == 1)
            { 
                ("内容不能为空", "警告", , );
                return;
            }
            for (int i = 0; i < rowCount; i++)
            { 
                for (int j = 0; j < columnCount; j++)
                {
                    var cellValue = [i, j].Value;
                 }
            }
//从数据库里读取到Excel
        SetCellText(, location, item.F_Name, true);
 /// <summary>
        /// 从数据库里读取到Excel
        /// </summary>
        /// <param name="workSheet"></param>
        /// <param name="coordinates">位置格式如A1 B2</param>
        /// <param name="coordValue">值</param>
        /// <param name="isBold">是否加粗</param>
        private void SetCellText(Worksheet workSheet, string coordinates, string coordValue, bool isBold)
        {
            [coordinates].Value = coordValue;
            [coordinates]. = isBold;
        }