|
Query |
Response |
|
1. If we use EntireColumn in place of custom ranges application getting hanged up and not able to export excel. So instead of EntireColumn I am limiting the datavalidation to be applied for certain range like A1:A5000. if i limit. at least i am able to generate excel |
Yes, that’s fine of limiting the data validation to improve the performance.
You can use either as,
datavalidation = worksheet.Range[range].DataValidation;
Or as, datavalidation = worksheet[range].DataValidation;
|
|
but still it is taking too much time around 3 mins. |
We understood your implementation and reproduced your scenario. Currently, we are checking on this issue with high priority. We will check the feasibility to reduce the total time for generating the Excel and let you know further details about whether XlsIO library support this much of data with less time, on 26th March 2020. |
|
2. Excel is occupying around 1 MB of file size even there are only columns headers for each worksheet.
So i was thinking is above issues are any where related to current implementation. As we have many sheets and more number of columns. Can xlsio library support this much data? |
|
Query |
Response | |
|
I am limiting the datavalidation to be applied for certain range like A1:A5000. if i limit. at least i am able to generate excel but still it is taking too much time around 3 mins.
|
Currently, we are validating on it with high priority. But due to complexity, we will update further details on 27th March 2020. | |
|
Excel is occupying around 1 MB of file size even there are only columns headers for each worksheet.
So i was thinking is above issues are any where related to current implementation. As we have many sheets and more number of columns. Can xlsio library support this much data? |
Yes, XlsIO library supports larger data. But can you please confirm us whether your file is having column headers alone? Check the file by pressing [Ctrl + End] and tell us the last cell address. It would be helpful to analyze further if you can share us the 1 MB file you are talking about. | |
|
How can i added Data Validation on column to allow only list of comma separated integers ex:(1,21,34) other than this pattern user should not allowed to enter any string or other garbage values. |
You can achieve any list validations similar to what we have done for Boolean. We have added data validation code to allow integers only from the list (1, 21, 34), to the previously given sample and it can be downloaded from the following link.
But the comma separated list cannot be added in data validation. However, we can check if that can be achieved through formula and get back to you on 27th March 2020.
The code snippet included in the sample can be found below.
Kindly let us know if this helps or if your requirement is different from this. Have a look into the below link too.
https://help.syncfusion.com/file-formats/xlsio/working-with-data-validation?cs-save-lang=1&cs-lang=asp.net%20core#custom-validation |
|
IDataValidation listvalidation = worksheet["D1:D5000"].DataValidation;
listvalidation.BeginUpdate();
listvalidation.AllowType = ExcelDataType.Formula;
listvalidation.FirstFormula = "=ISNUMBER(--SUBSTITUTE(D1,\",\",\"\"))";
listvalidation.EndUpdate(); |
|
No. of Data Tables |
Time taken before fix |
Time taken after fix |
|
2 |
23 seconds |
11 seconds |
|
5 |
52 seconds |
30 seconds |
|
10 |
1 minute 54 seconds |
1 minute 1 second |
|
workSheet.Range[range].NumberFormat = "@"; |
|
public IActionResult CreateDocument()
{
//Create an instance of ExcelEngine
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2016;
//Create a workbook
IWorkbook workbook = application.Workbooks.Create(1);
DataTable dataTable = GetDataTable();
FillTable(dataTable);
var worksheet = workbook.Worksheets.Create(dataTable.TableName);
//Number format is set to Text for column 3 and column 5
IStyle style = workbook.Styles.Add("NewStyle");
style.NumberFormat = "@";
worksheet.SetDefaultColumnStyle(3, style);
worksheet.SetDefaultColumnStyle(5, style);
IDataValidation intvalidation = worksheet["A1:A5"].DataValidation;
intvalidation.BeginUpdate();
intvalidation.AllowType = ExcelDataType.Integer;
intvalidation.EndUpdate();
IDataValidation realvalidation = worksheet["B1:B5"].DataValidation;
realvalidation.BeginUpdate();
realvalidation.AllowType = ExcelDataType.Formula;
realvalidation.FirstFormula = "=ISNUMBER(B1)";
realvalidation.EndUpdate();
IDataValidation boolvalidation = worksheet["C1:C5"].DataValidation;
boolvalidation.BeginUpdate();
boolvalidation.AllowType = ExcelDataType.User;
boolvalidation.ListOfValues = new string[] { "true", "false" };
boolvalidation.EndUpdate();
IDataValidation listvalidation = worksheet["D1:D5000"].DataValidation;
listvalidation.BeginUpdate();
listvalidation.AllowType = ExcelDataType.Formula;
listvalidation.FirstFormula = "=ISNUMBER(--SUBSTITUTE(D1,\",\",\"\"))";
listvalidation.EndUpdate();
//IDataValidation longvalidation = worksheet["E1:E5"].DataValidation;
//longvalidation.BeginUpdate();
//worksheet.Range["E1:E5"].NumberFormat = "@";
//longvalidation.EndUpdate();
worksheet.ImportDataTable(dataTable, true, 1, 1);
//Workaround to preserve the text along with its number format
IRange booleanRange = worksheet["C2:C5"];
foreach(IRange range in booleanRange)
{
string value = range.Value2.ToString();
if(value != "")
range.Formula = "=LOWER(" + value + ")";
}
var table = worksheet.ListObjects.Create(dataTable.TableName, worksheet.UsedRange);
table.BuiltInTableStyle = TableBuiltInStyles.TableStyleMedium6;
//Saving the Excel to the MemoryStream
MemoryStream stream = new MemoryStream();
workbook.SaveAs(stream);
//Set the position as '0'.
stream.Position = 0;
//Download the Excel file in the browser
FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/excel");
fileStreamResult.FileDownloadName = "Output2.xlsx";
return fileStreamResult;
}
} |