小编Zan*_*kul的帖子

C#OPENXML XLSX自定义列宽

C#新手在这里!

我需要创建一个小型控制台应用程序来将CSV文件转换为XLSX文件.

我有我的所有样式和数据,但我想在某些列上设置不同的(默认)宽度.经过一天的搜索和阅读后,我仍然无法弄清楚如何让它发挥作用.

作为一个例子,我想

  • 将列A和C设置为宽度为30
  • 将列D设置为宽度20

任何帮助或提示都会很棒.我的代码现在在下面

using System;
using System.Linq;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml;
using Microsoft.VisualBasic.FileIO;

namespace xml_test
{
    class Program
    {
        static void Main(string[] args)
        {          
            string xlsx_path = @"c:\test\test.xlsx";
            string CSV_Path = @"c:\test\test.csv";

            // Skal nok ha en try her i tilfellet et dolument er åpent eller noe slikt...
            using (var spreadsheet = SpreadsheetDocument.Create(xlsx_path, SpreadsheetDocumentType.Workbook))
            {
                spreadsheet.AddWorkbookPart();
                spreadsheet.WorkbookPart.Workbook = new Workbook();
                var wsPart = spreadsheet.WorkbookPart.AddNewPart<WorksheetPart>();
                wsPart.Worksheet = new Worksheet();                            
                SheetFormatProperties sheetFormatProperties = new SheetFormatProperties()
                { …
Run Code Online (Sandbox Code Playgroud)

c# openxml xlsx

13
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

openxml ×1

xlsx ×1