Hi
Attaching file that is creating issues initially in 2003 or 2007 excel.
Hi,
Thanks for your posting and using Aspose.Cells.
Please manually create your sample Excel file with desired Data Validation using Microsoft Excel and attach it here for our reference.
We will investigate it and provide you a sample code how to achieve the same thing using Aspose.Cells.
Thanks for your cooperation.
Please find the manually created XLS file
Any workaround for this issue.?
Hi,
Thanks for your posting and using Aspose.Cells.
I have looked into your Excel file but I am unable to grasp it completely. Could you please guide us with step by step instructions to let us know how you created this Data Validation List with formula and how your formula is working.
Once, we understand the inner working of your file and the steps to create it using Microsoft Excel, we will be in a better position to reproduce the same thing with Aspose.Cells code.
Thanks for your cooperation.
Hi,
Thanks for your posting and using Aspose.Cells.
Please see the following sample code. It creates a new worksheet and creates your desired list data validation and applies it to cell B1:B6 and saves the output in XLS and XLSX formats.
The list data validation works fine as expected. Please see the screenshot showing them working attached with this post for your reference.
I have also attached the output Excel files. I have run the sample code with the latest version: Aspose.Cells
for .NET v8.4.0.1.
C#
string filePath = @“F:\Shak-Data-RW\Downloads\CascadeListing±+Copy.xls”;
//Open source workbook
Workbook workbook = new Workbook(filePath);
//Add new worksheet
Worksheet sh = workbook.Worksheets.Add(“Test”);
//Add values from A1:A6
sh.Cells[“A1”].PutValue(“xeroxmodel1”);
sh.Cells[“A2”].PutValue(“xeroxmodel2”);
sh.Cells[“A3”].PutValue(“xeroxmodel1”);
sh.Cells[“A4”].PutValue(“xeroxmodel2”);
sh.Cells[“A5”].PutValue(“xeroxmodel1”);
sh.Cells[“A6”].PutValue(“xeroxmodel2”);
//Apply List Data Validation on B1:B6
CellArea area= CellArea.CreateCellArea(“B1”, “B6”);
int idx = sh.Validations.Add(area);
Validation v = sh.Validations[idx];
v.Formula1 = “=IF(SUBSTITUTE(CELL("contents",INDIRECT(ADDRESS(ROW(),COLUMN()-1)))," → ","")="",INDIRECT("BLANK"),INDIRECT(SUBSTITUTE(CELL("contents",INDIRECT(ADDRESS(ROW(),COLUMN()-1)))," → ","")))”;
v.Type = ValidationType.List;
//Autofit columns
sh.AutoFitColumns();
//Save in XLS and XLSX formats
workbook.Save(“output.xls”);
workbook.Save(“output.xlsx”);
Same issues exists for 2007 also. Can you pls check this issue, i have attached the 2007 excel file hereby.
Hi,
Thanks for your posting and using Aspose.Cells.
Please use the latest version: Aspose.Cells
for .NET v8.4.0.1 because we only fix issues if they are found in recent versions. Please use the formula with slash as escape characters. It is working fine as I have tested it and shown you in the above post.
If your issue still occurs with the latest version, then let us know your sample code and provide us any source excel file used in your code.
Also, you can load your source excel file yourself and observe the values or formulas using debug/watch windows etc.
Could you please check with 4.7.1.0…?
Hi,
Thanks for using Aspose.Cells.
Do you want me to try the code I have given in my above post with the older version?
Yes, Since i have no choice to upgrade aspose.cells to latest version, i need help to achieve my requirement using 4.7.1.0 version.
Hi,
Thanks for using Aspose.Cells.
I have tested this issue with the following sample code using the older version (4.7.1.0) and found that the older version contains a bug.
I have attached the output xls and xlsx files generated by it. In xls output, when you click data validation and click ok, it starts working, the same problem you faced earlier. And xlsx output is corrupt and does not open in Microsoft Excel.
So you have no choice but to use the latest version which works fine without any issue.
C#
string filePath = @“F:\Shak-Data-RW\Downloads\CascadeListing±+Copy.xls”;
//Open source workbook
Workbook workbook = new Workbook();
workbook.Open(filePath);
//Add new worksheet
Worksheet sh = workbook.Worksheets.Add(“Test”);
//Add values from A1:A6
sh.Cells[“A1”].PutValue(“xeroxmodel1”);
sh.Cells[“A2”].PutValue(“xeroxmodel2”);
sh.Cells[“A3”].PutValue(“xeroxmodel1”);
sh.Cells[“A4”].PutValue(“xeroxmodel2”);
sh.Cells[“A5”].PutValue(“xeroxmodel1”);
sh.Cells[“A6”].PutValue(“xeroxmodel2”);
//Apply List Data Validation on B1:B6
CellArea area = new CellArea();
area.StartRow = 0;
area.EndRow = 5;
area.StartColumn = 1;
area.EndColumn = 1;
int idx = sh.Validations.Add();
Validation v = sh.Validations[idx];
v.AreaList.Add(area);
v.Formula1 = “=IF(SUBSTITUTE(CELL(“contents”,INDIRECT(ADDRESS(ROW(),COLUMN()-1))),”->","")="",INDIRECT(“BLANK”),INDIRECT(SUBSTITUTE(CELL(“contents”,INDIRECT(ADDRESS(ROW(),COLUMN()-1))),"->","")))";
v.Type = ValidationType.List;
//Autofit columns
sh.AutoFitColumns();
//Save in XLS and XLSX formats
workbook.Save(“output.xls”);
workbook.Save(“output.xlsx”);
Thank You Very Much Shakeel Faiz.
Thank You Very Much,