这个是赋值的代码
sv.Columns[xlSheetConfig.StartColumnIndex + j - 1].CellType = spreadCodeStyle.Find(r["fcode"].ToString().ToLower()).CellType;
sv是activesheet ,xlSheetConfig.StartColumnIndex + j - 1 代表某列
spreadCodeStyle 是 NamedStyleCollection 储存了多个style
这个是我构建combo的代码, 试验的时候请自行配置
string[] dataItem = new string[itemtable.Rows.Count];
string[] datatext = new string[itemtable.Rows.Count];
for (int i = 0; i < itemtable.Rows.Count; i++)
{
dataItem[i] = itemtable.Rows[i]["xxdm"].ToString();
datatext[i] = itemtable.Rows[i]["xxdmhy"].ToString();
}
codestyle.Name = row[0].ToString().ToLower();
FarPoint.Win.Spread.CellType.ComboBoxCellType comboBoxCellType = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
comboBoxCellType.ButtonAlign = FarPoint.Win.ButtonAlign.Right;
comboBoxCellType.EditorValue = FarPoint.Win.Spread.CellType.EditorValue.ItemData;
comboBoxCellType.ItemData = dataItem;
comboBoxCellType.Items = datatext;
codestyle.VerticalAlignment = CellVerticalAlignment.Center;
codestyle.HorizontalAlignment = CellHorizontalAlignment.Center;
codestyle.CellType = comboBoxCellType;
spreadCodeStyle.Add(codestyle);
这个是我导出 的代码
fpspread.SaveExcel(saveFileDlg.FileName, FarPoint.Excel.ExcelSaveFlags.UseOOXMLFormat); |