我写成"宋体"或者Arial,导出来的都是无效字符字体
![
///////设置整体的字体、字号及颜色//////
Font ft;
ft.AttachDispatch(m_ExlRge.GetFont());
ft.SetName(_variant_t("宋体"));//字体
ft.SetColorIndex(_variant_t((long)11));//字的颜色
ft.SetSize(_variant_t((long)12));//字号
///////////设置标题字体及颜色//////////
m_ExlRge.AttachDispatch(m_ExlSheet.GetRange(_variant_t("A1"),_variant_t("D1")));
ft.AttachDispatch(m_ExlRge.GetFont());
ft.SetBold(_variant_t((long)1));//粗体
ft.SetSize(_variant_t((long)13));
ft.SetColorIndex(_variant_t((long)2));
CellFormat cf;
cf.AttachDispatch(m_ExlRge.GetCells());
呜呜,参数类型是不一样的,SetFont函数的字体类型是LPSTR,所以我CString类的字符串CString strFontName="宋体";,然后强制转换为LPSTR FontName=(LPSTR)(LPCTSTR)strFontName;
Excel_example.SetFont(1,FontName,16,true); 为什么不对呢
setfont函数是
void CExport2Excel::SetFont(long iRow, LPSTR pszFontName, int iFontSize, bool bBold)
{
CString strT;
strT.Format(L"%d:%d", iRow, iRow);
CRange tRange;
tRange.AttachDispatch(m_rangeExcel.get_Range(_variant_t(strT.GetBuffer()), vtMissing), true);
tRange.Select();
CFont0 tFont;
tFont.AttachDispatch(tRange.get_Font());
if (bBold)
tFont.put_Bold(_variant_t(true));
else
tFont.put_Bold(_variant_t(false));
if (pszFontName != NULL)
tFont.put_Name(_variant_t(pszFontName));
tFont.put_Size(_variant_t(iFontSize));
tFont.ReleaseDispatch();
tRange.ReleaseDispatch();
}