彩票走势图

文档转换攻略第六弹!国产工具Spire.XLS 2020格式转换全新攻略来啦!

原创|使用教程|编辑:李显亮|2020-11-26 10:06:27.730|阅读 213 次

概述:Spire系列文档处理API是国产开发工具中功能可媲美Aspose的强大控件,帮助开发者轻松将文档功能集成到应用程序中。临近年终,小编为您倾情献上Spire.XLS在.NET中格式转换的示例教程,记得收藏哦!

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

将文档从一种格式转换为另一种格式是Spire.XLS的主要功能之一。这种转换只不过是加载和保存操作的组合。因此,使用Spire.XLS可以将文档从任何受支持的加载格式转换为任何受支持的保存格式。

本文整理了包括在C#中以下文件格式的转换指南,希望对您有所帮助:

>>你可以点击这里下载Spire.XLS for .NET测试体验。

(篇幅较长,建议收藏阅读)

Excel转PDF

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Xls;

namespace ToPDF
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx", ExcelVersion.Version2010);
            workbook.SaveToFile("result.pdf", Spire.Xls.FileFormat.PDF);
         }
    }
}

Excel转HTML

using Spire.Xls;
namespace Xls2Html

{
    class Program
    {
        static void Main(string[] args)
        {
            //load Excel file
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"..\..\test.xls");
            
            //convert Excel to HTML
            Worksheet sheet = workbook.Worksheets[0];
            sheet.SaveToHtml("sample.html");

            //Preview HTML
            System.Diagnostics.Process.Start("sample.html");
        }
    }
}

Excel转图像

using Spire.Xls;
namespace Xls2Image

{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"..\..\test.xls");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.SaveToImage("sample.jpg");
        }
    }
}

Excel转CSV

using Spire.Xls;
namespace xls2csv
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"..\ExceltoCSV.xls");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.SaveToFile("sample.csv", ",", Encoding.UTF8);
        }
    }
}

CSV转Excel

using Spire.Xls;

namespace csvtoxls
{
    class Program
    {
        static void Main(string[] args)
        {
         Workbook workbook = new Workbook();
         workbook.LoadFromFile(@"D:\michelle\my file\csv2xls.csv", ",", 1, 1);
         Worksheet sheet = workbook.Worksheets[0];
         sheet.Name = "csv to excel";
         //set the backgroundcolor=LightBlue of Range["A1:E1"]
         sheet.Range["A1:E1"].Style.Color = Color.Chocolate;
         //set the backgroundcolor=LightBlue of Range["A2:E6"]
         sheet.Range["A2:E6"].Style.Color = Color.SpringGreen;
         //set the backgroundcolor=Silver of Range["A7:E12"]
         sheet.Range["A7:E12"].Style.Color = Color.SkyBlue;
         //set the backgroundcolor=Silver of Range["A13:E19"]
         sheet.Range["A13:E19"].Style.Color = Color.Yellow;
         workbook.SaveToFile("result.xls", ExcelVersion.Version97to2003);        
        }
    }
}

Excel转文本

using Spire.Xls;
namespace Excel_to_Txt
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"..\ExceltoTxt.xls");
            Worksheet sheet = workbook.Worksheets[0];
            sheet.SaveToFile("ExceltoTxt.txt", " ", Encoding.UTF8);
        }
    }
}

Excel转XPS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Xls;

namespace ExceltoXPS
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook(); 
            workbook.LoadFromFile("sample.xlsx", ExcelVersion.Version2010);
         
            workbook.SaveToFile("result.xps", Spire.Xls.FileFormat.XPS);
        }
    }
}

Excel转.ods

using Spire.Xls;

namespace Convert_Excel_to_ODS
{
    class Program
    {
        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("Sample.xlsx");
            workbook.SaveToFile("Result.ods",FileFormat.ODS);
        }
    }
}
如果您有任何疑问或需求,请随时,我们很高兴为您提供查询和咨询
标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP