[英]How to read a .csv file with C# Excel-DNA
我想使用visual-dna Excel插件讀取.csv文件(在顯示結果之前,它需要C#內置函數處理)。 誰知道如何更新此代碼,以便我可以將excel數組作為輸出(當然是在Excel中)?
Excel無法將以下代碼識別為數組。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ExcelDna.Integration;
using System.IO;
namespace MyExcelDNALibrary
{
public class Class1
{
[ExcelFunction(Name = "readcsv")]
public static object[] loadCsvFile(string filePath)
{
return File.ReadLines(filePath).Where(line => line != "").Select(x => x.Split(',')).ToArray();
}
}
}
我認為您正在返回一個字符串數組數組。 Excel-DNA不支持此類型。 將方法返回類型更改為2D object[,]
數組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.