描述:
VC控制EXCEL过程中,当需要合并单元格时,弹出提示信息框,请问如何用程序控制此对话框不弹出,另外还有如何用VC设置单元格的字体、颜色、居中状态等?谢谢
解决方案1:
学习!
解决方案2: 在Excel中录宏,然后把宏的VBA代码转换成VB or VC 代码,很简单
Sub 宏1()
'
' 宏1 Macro
' zhp80 记录的宏 2004-4-21
'
'
Range("A1:C1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Selection.Merge
Range("A2").Select
With Selection.Font
.Name = "华文隶书"
.Size = 12
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
With Selection.Font
.Name = "华文隶书"
.Size = 18
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Selection.Font.Bold = True
Selection.Font.ColorIndex = 45
End Sub
先用ClassWizard从Office目录中导入Excel9.olb,并添加相就的类到VC中
_Application *ExcelApp = new _Application;
ExcelApp->CreateDispatch("excel.application");
//设置为显示
ExcelApp->SetVisible(TRUE);
//得到WorkBooks
Workbooks ExcelBook=ExcelApp->GetWorkbooks();
Sheets ExcelSheet=ExcelBook.Add(vtOptional1);
_Workbook workBook;
_Worksheet workSheet;
Range range;
workBook.AttachDispatch(ExcelApp->GetApplication());
ExcelSheet=workBook.GetSheets();
////////////////////////////////////////////
workSheet=ExcelSheet.GetItem(COleVariant((short)1));
workSheet.Activate();
Range myallrange=workSheet.GetRange(COleVariant("A1"),COleVariant("E1"));
//myallrange.BorderAround(COleVariant((short)1),(long)2,(long)1,vtOptional);
myallrange.SetHorizontalAlignment(COleVariant((short)3));
myallrange.Merge(COleVariant((short)1));
myallrange.SetValue(COleVariant("这里写标题"));
nRowCount=m_grid.GetRows();
nColCount=m_stockgrid.GetCols();
Range myrange=workSheet.GetRange(COleVariant("A1"),COleVariant("A1"));
myrange.SetValue(COleVariant("单元格内容"));
myrange.BorderAround(COleVariant((short)1),(long)2,(long)1,vtOptional);
myrange.SetHorizontalAlignment(COleVariant((short)3));
myrange.SetVerticalAlignment(COleVariant((short)2));
myrange.SetColumnWidth(COleVariant((short)15));
delete ExcelApp;
GZ