Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88066

Is it possible to read Excel data from specific cells using PX.Data.XLSXReader?

$
0
0

Is it possible to read Excel data from specific cells using PX.Data.XLSXReader? I'm trying to read a specific column from an Excel file using Acumatica's XLSXReader library but I have been unable to find a function to get the information of a specific cell(s) - e.g. H7. It would appear that I need to define an index for the columns in order to iterate and get the information. However, in my case the excel file does not include information in the first row, and we are unable to modify it because it's automatically generated by a third party. This is my action:

    [PXUIField(DisplayName = "Upload Data", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Visible = true)]
    [PXButton()]
    public virtual IEnumerable uploadFileBatch(PXAdapter adapter)
    {
        string complete = "";
        if (this.NewFilePanel.AskExt() == WebDialogResult.OK)
        {
            PX.SM.FileInfo info = PXContext.SessionTyped<PXSessionStatePXData>().FileInfo[SessionKey] as PX.SM.FileInfo;
            byte[] bytes = info.BinData;
            List<string> pONotFound = new List<string>();
            using (PX.Data.XLSXReader reader = new XLSXReader(bytes))
            {
                reader.Reset();
                Dictionary<String, Int32> indexes = reader.IndexKeyPairs.ToDictionary(p => p.Value.ToUpper(), p => p.Key);
                while (reader.MoveNext())
                {
                    //This is correct when there is info in the first row with those titles
                    string data = reader.GetValue(indexes["TITLE"]).Trim() + "\n";
                    //However I would like to do something like this
                    string data2 = reader.GetValue("H7").Trim() + "\n";
                }
            }
        }
    }

Also, I have noticed that when I don't include

 Dictionary<String, Int32> indexes = reader.IndexKeyPairs.ToDictionary(p => p.Value.ToUpper(), p => p.Key);

the code doesn't iterate with

 reader.MoveNext()

I understand why Acumatica uses the first row to identify the columns and help with the mapping during the upload of documents - but I'm thinking of managing the library with more flexibility - if possible.


Viewing all articles
Browse latest Browse all 88066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>