locked
Suggested procedure for user data upload RRS feed

  • Question

  • User310927902 posted

    I am contemplating writing an asp.net core web app that allows users to upload data for validation and backend processing. The user data exist in Excel documents, the start and end of the data is user specific, however the row format is explicit. I want to be able to provide a means for them to get their data in the web site and see what might look like a GridView in Windows Forms with individual cell error checking. So if they bulk select a thousand lines but only 3 errors are present, they can navigate to each erroneous cell and resolve and commit it.

    I thought simply uploading the Excel doc and writing a parser with an existing Excel library, but maybe a copy and paste pattern might be better?

    What is an optimal control that facilitates this type of workflow?

    Thanks!

    Wednesday, April 25, 2018 8:55 PM

All replies

  • User283571144 posted

    Hi Ritmo2k,

    According to your description, I couldn't understand your requirement clearly.

    Do you mean you want to read the excel's data in asp.net core web application?

    After reading the data, you want to check the data in the excel?

    If this is your requirement, I suggest you could try to use ClosedXML package to achieve your requirement.

    You could read the data from excel into datatable firstly.

    Then you could write your own logic to validate each row's data.

    More details about how to read data from excel and fill into datatable, you could refer to below codes:

                string filePath = @"D:\test.xlsx";
                using (XLWorkbook workBook = new XLWorkbook(filePath))
                {
                    //Read the first Sheet from Excel file.
                   IXLWorksheet workSheet = workBook.Worksheet(1);
                    //Create a new DataTable.
                    DataTable dt = new DataTable();
                    //Loop through the Worksheet rows.
                    bool firstRow = true;
                    foreach (IXLRow row in workSheet.Rows())
                    {
                        //Use the first row to add columns to DataTable.
                        if (firstRow)
                        {
                            foreach (IXLCell cell in row.Cells())
                            {
                                dt.Columns.Add(cell.Value.ToString());
                            }
                            firstRow = false;
                        }
                        else
                        {
                            //Add rows to DataTable.
                            dt.Rows.Add();
                            int i = 0;
                            foreach (IXLCell cell in row.Cells())
                            {
                                dt.Rows[dt.Rows.Count - 1][i] = cell.Value.ToString();
                                i++;
                            }
                        }
    
                    }
    

    Result:

    Best Regards,

    Brando

    Thursday, April 26, 2018 7:34 AM
  • User310927902 posted

    Hi Brando,
    Sorry about the lack of clarity, I have a set of users who will have one or more Excel documents with tabular data that I need.

    The column specification is well defined, however the start and end row varies (some users have a header on row 3, some users have some extraneous data somewhere after the end of actual data).

    I am aware I can create an upload control and provide a user a way to upload the document. Parsing server side is not a problem.

    I am more concerned with how I can provide a richer environment. Even if i tell a user you need to enter the start and end position, no one understand that. And if I tell them on row 125 you have an error in column D and describe it, no one will read and understand that.

    I was wondering if a means where I could present a tabular control like a GridView in Windows Forms where they could copy and paste their data into. Then my hopes would be to highlight cells in error, that way they could incrementally fix the data until it validated?

    Does that sound plausible?

    Thursday, April 26, 2018 2:32 PM