A community member has associated this post with a similar question:
DocumentFormat.OpenXml.Spreadsheet while copying from existing excel apply validation if existing excel has hyperlinks download file not opened
Only moderators can edit this content.
DocumentFormat.OpenXml.Spreadsheet while copying from existing excel apply validation if existing excel has hyperlinks and datavalidation download file not opened
string MyFile = @"C:\Users\Desktop\temp\sample.xlsm";
using (SpreadsheetDocument myDoc = SpreadsheetDocument.Open(MyFile, true))
{
WorkbookPart wbPart = myDoc.WorkbookPart;
Hyperlinks hyperlinks1 = new Hyperlinks();
//var sheetData = new DocumentFormat.OpenXml.Spreadsheet.SheetData();
WorksheetPart worksheetPart = GetWorksheetPartByName(myDoc, "Test");
DataValidations dataValidations = new DataValidations();
DataValidation dataValidation = new DataValidation()
{
Type = DataValidationValues.List,
AllowBlank = true,
SequenceOfReferences = new ListValue<StringValue>() { InnerText = "A1:A1048576" }
};
Formula1 formula = new Formula1();
formula.Text = "\"FirstChoice,SecondChoice,ThirdChoice\"";
dataValidation.Append(formula);
dataValidations.Append(dataValidation);
//insert the dataValidations to the correct place
worksheetPart.Worksheet.InsertBefore(dataValidations, worksheetPart.Worksheet.Descendants<PageMargins>().FirstOrDefault());
}
Console.WriteLine("File Saved to " + MyFile);