This project has moved. For the latest updates, please go here.

DataValidation Pb

Feb 20, 2012 at 12:22 PM
Edited Feb 20, 2012 at 1:43 PM

I've a lot of difficulties using the versions above v0.59

i expect to extract all cells containing validation errors but there is not errors using the dll version > v0.59.

The v0.59 give me all the error cells.

Do you have any another post concerning this problem or are the methods radically differents ?

Thanks, and sorry for my very bad english

best regards

Coordinator
Feb 20, 2012 at 3:15 PM

Please post a piece of code that reproduces the error.

Feb 21, 2012 at 7:42 AM


For exemple, this kind of code works perfectly with the v0.59

            if (DataRange.Worksheet.DataValidations.Count() > 0)
            {
                DataRange.Cells()
                    .Where(c => c.DataValidation.ErrorTitle.Length > 0) // Each DataValidation error have been detected
                    .ForEach(c =>
                        {
                            string exp = @"\d"; // Extrac num value
                            if (Regex.Match(c.DataValidation.ErrorTitle, exp).Length > 0)
                                int.TryParse(Regex.Match(c.DataValidation.ErrorTitle, exp).Value, out niveau);

                            parent.WrkBookAnomalies.Add(
                                new ClassAnomalie()
                                {
                                    CellReference = c.Address.ToString(),
                                    Description = c.DataValidation.ErrorMessage,
                                    NomColonne = this.WrkSheet.Row(Constantes.NO_LIGNE_DATA)
                                                .Cell(c.Address.ColumnNumber).Value.ToString(),
                                    NomFeuille = this.WrkSheet.Name,
                                    XLCell = c,
                                    Niveau = niveau
                                });
                        });
            }

Do you follow me ?

Thanks

Coordinator
Feb 21, 2012 at 3:28 PM

I don't understand the problem, the following works just fine:

            var wb = new XLWorkbook();
            var ws = wb.Worksheets.Add("People");

            ws.FirstCell().SetValue("Categories")
                .CellBelow().SetValue("A")
                .CellBelow().SetValue("B")
                .CellBelow().SetValue("")
                .CellBelow().SetValue("D");

            var table = ws.RangeUsed().CreateTable();

            var dv = table.DataRange.DataValidation;
            dv.TextLength.GreaterThan(0);
            dv.ErrorTitle = "Error";

            foreach (var c in table.DataRange.Cells(c => c.HasDataValidation))
            {
                Console.WriteLine(String.Format("Cell({0}) = '{1}' ErrorTitle: {2}", 
                    c.Address.ToStringRelative(),
                    c.GetString(),
                    c.DataValidation.ErrorTitle));
            }

            Console.ReadKey();

Feb 21, 2012 at 3:42 PM

Thank you for your reply,

I have didn’t seen HasDataValidation method before I’m sorry

And I can’t find it on http://closedxml.codeplex.com/documentation

I think that I have to find a real documentation on ClosedXML !

Thanks again.

HP

De : mdeleon [email removed]
Envoyé : mardi 21 février 2012 17:28
À : PEYRAUD Hervé
Objet : Re: DataValidation Pb [closedxml:330987]

From: mdeleon

I don't understand the problem, the following works just fine:

            var wb = new XLWorkbook();
            var ws = wb.Worksheets.Add("People");
 
            ws.FirstCell().SetValue("Categories")
                .CellBelow().SetValue("A")
                .CellBelow().SetValue("B")
                .CellBelow().SetValue("")
                .CellBelow().SetValue("D");
 
            var table = ws.RangeUsed().CreateTable();
 
            var dv = table.DataRange.DataValidation;
            dv.TextLength.GreaterThan(0);
            dv.ErrorTitle = "Error";
 
            foreach (var c in table.DataRange.Cells(c => c.HasDataValidation))
            {
                Console.WriteLine(String.Format("Cell({0}) = '{1}' ErrorTitle: {2}", 
                    c.Address.ToStringRelative(),
                    c.GetString(),
                    c.DataValidation.ErrorTitle));
            }
 
            Console.ReadKey();
Coordinator
Feb 21, 2012 at 4:10 PM

Now that I double check it, it correctly identifies the cells with data validations but then the cell's data validation is blank. I'll fix it.

Coordinator
Feb 21, 2012 at 4:11 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.