如何将数据保存到excel由linq excel [英] How to save data to excel by linq to excel
本文介绍了如何将数据保存到excel由linq excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从Excel表格中成功获取数据使用LinqToExcel但是我想用LinqToExcel将日期保存到Excel。
我尝试了什么:
public void ExcelWrite()
{
string pathToExcelFile =
+ @ C:\\Users\\Admin\\Desktop\\Excl.xlsx;
string sheetName =Sheet1;
var excelFile = new ExcelQueryFactory(pathToExcelFile);
//添加列映射:
excelFile.AddMapping(名称,艺术家名称);
excelFile.AddMapping(标题,专辑标题);
var artistAlbums =来自excelFile.Worksheet< PropertyClass>(sheetName)选择一个;
foreach(艺术家阿尔法中的var a)
{
string artistInfo =艺术家姓名:{4};专辑:{5};
Console.WriteLine(artistInfo,a.Name,a.Title);
}
}
解决方案
根据介绍 [ ^ ],该项目是旨在:
检索数据使用LINQ来自电子表格和csv文件
没有任何迹象表明此库可用于修改电子表格。
为此,您需要使用支持它的库。例如:
I am successfully get data from Excel sheet usig LinqToExcel But I want to save date to Excel with LinqToExcel.
What I have tried:
public void ExcelWrite() { string pathToExcelFile = "" + @"C:\\Users\\Admin\\Desktop\\Excl.xlsx"; string sheetName = "Sheet1"; var excelFile = new ExcelQueryFactory(pathToExcelFile); // ADD COLUMN MAPPINGS: excelFile.AddMapping("Name", "Artist Name"); excelFile.AddMapping("Title", "Album Title"); var artistAlbums = from a in excelFile.Worksheet<PropertyClass>(sheetName) select a; foreach (var a in artistAlbums) { string artistInfo = "Artist Name: {4}; Album: {5}"; Console.WriteLine(artistInfo, a.Name, a.Title); } }
解决方案
According to the introduction[^], that project is designed to:
Retrieve data from spreadsheets and csv files by using LINQ
There is nothing to indicate that this library can be used to modify a spreadsheet.
To do that, you'll need to use a library that supports it. For example:
这篇关于如何将数据保存到excel由linq excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文