因此,找到了Sergey Marenich的有关如何使用XLSXReader读取excel的文章。 例如https://asiablog.acumatica.com/2016/03/reading-excel-file-acumatica.html
我有一个很棒的图形,还有一个非常漂亮的按钮来“解析”文件,并将文件附加到我的实体上。
但是,当我尝试解析Excel时,我只得到工作表的LAST行 数据格式(非常粗略): 一堆我不在乎的垃圾(图片,约10行标题乐趣) 我做了几个区域(我打算在A列上进行匹配,如果这是我想要的值,请使用该行的其他元素) 然后还有更多我不关心的垃圾(签名图像,另外10行摘要内容)
有什么想法吗?
非常粗糙的图形代码:
Guid[] files = PXNoteAttribute.GetFileNotes(this.LabResult.Cache, this.LabResult.Cache.Current);
if (files != null && files.Length > 0)
{
foreach (Guid fileID in files)
{
var fm = PXGraph.CreateInstance<PX.SM.UploadFileMaintenance>();
PX.SM.FileInfo fi = fm.GetFile(fileID);
if (Log.IsInfoEnabled) Log.LogInfo(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} {1}", "0275b555-9e5b-4b59-8378-991bef88ae62", fi.Name));
if (fi.Name.ToUpperInvariant().EndsWith(".xlsx".ToUpperInvariant()))
{
// Only want Excel files to go through this, since it's excel specific
Trace.TraceInformation(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", "138fcfe4-de54-4b9d-8846-43a62123c28a"));
// Byte[] bytes = fi.BinData;
using (PX.Data.XLSXReader reader = new XLSXReader(fi.BinData))
{
Trace.TraceInformation(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", "b637b60a-96ce-4a4c-8a42-039cb625f578"));
//Initialising Reader
reader.Reset();
Trace.TraceInformation(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", "79abfd64-509d-4d88-89db-c22cd77d45ea"));
//Creating a dictionary to find column index by name
// Dictionary<String, Int32> indexes = reader.IndexKeyPairs.ToDictionary(p => p.Value, p => p.Key);
//Skipping first row with column names.
// reader.MoveNext();
int cntr = 15;
// while (reader.MoveNext())
while(cntr-- > 0)
{
reader.MoveNext();
if (Log.IsInfoEnabled) Log.LogInfo(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}", "55e32c69-4bed-411a-9fdd-f15d23305c8a"));
//Processing row
if (Log.IsInfoEnabled) Log.LogInfo(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} '{1}'", "a26f6b05-e942-4d7a-bd32-80ba995549b0", reader.GetValue(RowTypeName)));
if (Log.IsInfoEnabled) Log.LogInfo(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0} '{1}' '{2}' '{3}'", "ab31a386-1b3b-4c99-89ba-f10055fd3022", reader.GetValue(1), reader.GetValue(2), reader.GetValue(3)));
使用Guid进行了很多评论,我可以验证每个元素是否都符合要求。 当我尝试使用movenext时,它从未进入循环。因为我知道我有15条以上的线,所以尝试了 结束于〜15行 ab31a386-1b3b-4c99-89ba-f10055fd3022'''最后一个文本行'''