我需要使用openXml使用特定列表作为excel文件的列/列中的源创建下拉列表.
我使用以下代码,
SpreadsheetDocument spreadSheetDocument = SpreadsheetDocument.Open("C:\\Users\\Harun.TV\\Desktop\\OpenXml\\1.xlsx",true);
WorkbookPart workbookpart = spreadSheetDocument.WorkbookPart;
Workbook workbook=workbookpart.Workbook;
WorksheetPart worksheetPart=workbookpart.WorksheetParts.First();
DataValidations dataValidations1 = new DataValidations();
DataValidation dataValidation2 = new DataValidation() { Formula1 = new Formula1("'mySheet'!$A$1:$A$4"), Type = DataValidationValues.List, AllowBlank = true, ShowInputMessage = true, ShowErrorMessage = true, SequenceOfReferences = new ListValue<StringValue>() { InnerText = "A4:B4" } };
Formula1 formula12 = new Formula1();
formula12.Text = "$A$1:$A$3";
dataValidations1.Append(dataValidation2);
worksheetPart.Worksheet.Append(dataValidations1);
workbookpart.Workbook.Save();
spreadSheetDocument.Close();
Run Code Online (Sandbox Code Playgroud)
并且它会在打开excel时抛出错误.日志如下,
<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"> <logFileName>error055840_01.xml</logFileName>
<summary>Errors were detected in file 'C:\Users\Harun.TV\Desktop\OpenXml\6.xlsx'</summary>
-<removedParts summary="Following is …Run Code Online (Sandbox Code Playgroud)