Hi Umair,Good day to you.Before we start to work with this, we would like to know the following details,1. Could you please confirm whether you need to add custom property in cell on server side and use it in client side. And also please confirm whether you need to access the same custom property in server side.2. Please share your exact use case.Could you please get back to us with the above details? So that we can sort out and provide you the better solution quickly.Could you please check the below documentation link for Value and Value2 property usage in XlsIO.Regards,Saranya D
public IActionResult Open(IFormCollection openRequest)
{
ExcelEngine excelEngine = new ExcelEngine();
IWorkbook workbook;
Stream memStream = (openRequest.Files[0] as IFormFile).OpenReadStream();
workbook = excelEngine.Excel.Workbooks.Open(memStream, ExcelOpenType.Automatic);
List<CustomArgs> customArgs = GetCustomArgs(workbook);
MemoryStream outputStream = new MemoryStream();
workbook.SaveAs(outputStream);
IFormFile formFile = new FormFile(outputStream, 0, outputStream.Length, "", openRequest.Files[0].FileName); // converting MemoryStream to IFormFile
OpenRequest open = new OpenRequest();
open.File = formFile;
var content = Workbook.Open(open);
content = content.Insert(content.Length - 2, ", \"customArgs\":" + JsonConvert.SerializeObject(customArgs)); // Adding customArgs to the string returned by Open method
return Content(content);
}
private List<CustomArgs> GetCustomArgs(IWorkbook workbook)
{
List<CustomArgs> customArgs = new List<CustomArgs>();
IWorksheet worksheet;
int i = 0, cnt = workbook.Worksheets.Count;
while (i < cnt)
{
worksheet = workbook.Worksheets[i];
for (int j = 0; j < worksheet.UsedRange.LastRow; j++)
{
for (int k = 0; k < worksheet.UsedRange.LastColumn; k++)
{
customArgs.Add(new CustomArgs { address = RangeImpl.GetCellName(k + 1, j + 1), customValue = "custom value for " + RangeImpl.GetCellName(k + 1, j + 1), sheetIndex = i });
}
}
i++;
}
return customArgs;
} |
public class CustomArgs
{
public string customValue { get; set; }
public string address { get; set; }
public int sheetIndex { get; set; }
} |
<label>Custom Args:</label>
<div id="customvalue"></div>
<ejs-spreadsheet #default [openUrl]="openUrl" [allowOpen]="true" [saveUrl]="saveUrl" (created)="onCreated($event)" (select)="onSelect($event)" (openComplete)="onOpenComplete($event)">
</ejs-spreadsheet> |
export class AppComponent {
@ViewChild('default')
public spreadsheetObj: SpreadsheetComponent;
public customArgs: any;
onCreated() {
……
}
onOpenComplete(args: any) {
this.customArgs = args.response.data.customArgs;
}
onSelect(args: SelectEventArgs) {
for (var i = 0; i < this.customArgs.length; i++) {
if (this.spreadsheetObj.activeSheetTab - 1 === this.customArgs[i].sheetIndex && args.range === this.customArgs[i].address + ":" + this.customArgs[i].address) {
document.getElementById("customvalue").innerHTML = this.customArgs[i].customValue;
break;
}
}
}
}
|