AsposeHelper.cs

AsposeHelper.cs 是一个C#静态类,提供Aspose库的辅助方法,用于操作Word文档(如打开、保存、获取和设置页眉页脚)以及Excel工作簿(如打开、保存、获取数据表、设置单元格)。该类包含处理段落、页眉页脚、工作表和单元格的静态方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System.Data;
using System.IO;
using Aspose.Cells;
using Aspose.Words;
using Aspose.Words.Tables;

namespace DAQ.BaseLib.Helper
{
    using Cell = Aspose.Cells.Cell;
    using DocSaveFormat = Aspose.Words.SaveFormat;
    using XlsSaveFormat = Aspose.Cells.SaveFormat;

    /// <summary>
    /// 表格页眉页脚
    /// </summary>
    public enum HeaderFooterPart
    {
        Left = 0,
        Center = 1,
        Right = 2
    }

    public static class AsposeHelper
    {
        #region Words

        /// <summary>
        /// 打开指定路径文档
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static Document OpenDocument(string path)
        {
            return File.Exists(path) ? new Document(path) : null;
        }

        /// <summary>
        /// 将已打开文档保存至指定位置
        /// </summary>
        /// <param name="document"></param>
        /// <param name="path"></param>
        /// <param name="saveFormat"></param>
        public static void Save(Document document, string path, DocSaveFormat saveFormat)
        {
            document.Save(path, saveFormat);
        }

        #region __章节段落
        /// <summary>
        /// 获取指定章节
        /// </summary>
        /// <param name="document"></param>
        /// <param name="sectionIndex"></param>
        /// <returns></returns>
        public static Section GetSection(Document document, int sectionIndex)
        {
            return document.Sections[sectionIndex];
        }

        /// <summary>
        /// 获取指定段落
        /// </summary>
        /// <param name="document"></param>
        /// <param name="sectionIndex"></param>
        /// <param name="paragraphIndex"></param>
        /// <returns></returns>
        public static Paragraph GetParagraph(Document document, int sectionIndex, int paragraphIndex)
        {
            return GetSection(document, sectionIndex).Body.Paragraphs[paragraphIndex];
        }

        #endregion

        #region __页眉页脚
        /// <summary>
        /// 获取页眉页脚
        /// </summary>
        /// <param name="document"></param>
        /// <param name="getHeader"></param>
        /// <returns></returns>
        public static string GetHeaderFooter(Document document, bool getHeader)
        {
            for (var i = 0; i < document.Sections.Count; i++)
            {
                var section = document.Sections[i];
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值