0
我正在使用ExcelPackage DLL從.net應用程序創建Excel。如何以編程方式在Excel表格中添加下拉菜單?
我想添加下拉列表中的一個Excel表單的列。如何添加它?
此外我想對單元格值進行一些格式更改。
我正在使用ExcelPackage DLL從.net應用程序創建Excel。如何以編程方式在Excel表格中添加下拉菜單?
我想添加下拉列表中的一個Excel表單的列。如何添加它?
此外我想對單元格值進行一些格式更改。
嘗試spreadsheetgear ....
protected void AddDropDownToExcel(string path)
{
//path gives the location where u have created excel file
string fileName = path.Replace("\\", "\\\\");
// F is the column name where you want to place the dropdown
string RowCount = "F" + gridrowcount;
// Open Excel and get first worksheet.
var workbook = application.Workbooks.Open(fileName);
var worksheet = workbook.Worksheets[1] as Microsoft.Office.Interop.Excel.Worksheet;
// Set range for dropdownlist
var rangeNewStatus = worksheet.get_Range("F2", RowCount);
rangeNewStatus.ColumnWidth = 20;
rangeNewStatus.Validation.Add(Microsoft.Office.Interop.Excel.XlDVType.xlValidateList, Microsoft.Office.Interop.Excel.XlDVAlertStyle.xlValidAlertStop,
Microsoft.Office.Interop.Excel.XlFormatConditionOperator.xlBetween, "dropdownlistitem1, dropdownlistitem2");
// Save.
workbook.Save();
workbook.Close(Microsoft.Office.Interop.Excel.XlSaveAction.xlSaveChanges, Type.Missing, Type.Missing);
application.Quit();
}
還包括DLL的Microsoft.Office.Interop.Excel。謝謝 – 2013-01-10 21:55:40