上面的问题如果使用C++ActiveX控件需要进行以下操作才能将指定行合并。
需要先进行
TxControl->utSelStar(TxControl->GetTableCellStar(10, 1, 5));
TxControl->utSelLength(1);
这时候需要再设置一次,否则SelStar无法保存进去。
TxControl->utSelStar(TxControl->GetTableCellStar(10, 1,5) - 1);
TXControl->utSelLength(GetString(TxControl->GetTableCellText(10, 1, 5)).getLength() + nLength);
以下是部分代码,进行设置后无法插入图片。麻烦看看是不是某个样式导致不能插入。
struct PageSets
{
void Set()//默认A4
{
width = 11906;
heigth = 16838;
MarinLeft = 1800;
MarinRight = 1800;
MarinTop = 1440;
MarinBottom = 1440;
}
int width;
int heigth;
int MarinLeft;
int MarinRight;
int MarinTop;
int MarinBottom;
};
void CWordExportManger::SetPageAligment( PageSets pageSets )
{
_FileClass->utPageWidth(pageSets.width);//标准A4
_FileClass->utPageMarginL(pageSets.MarinLeft);
_FileClass->utPageMarginR(pageSets.MarinRight);
_FileClass->utPageMarginT(pageSets.MarinTop);
_FileClass->utPageMarginB(pageSets.MarinBottom);
_FileClass->utPageHeight(pageSets.heigth);//标准A4
}
BOOL CWordExportManger:utSelText( CString strText, StyleType type)
{
_bstr_t bstrText = _FileClass->GetText();
CString strAllText = GetString(bstrText);
if (!strAllText.IsEmpty())
{
_FileClass->PutSelStart(strAllText.GetLength());
_FileClass->PutSelLength(1);
}
_FileClass->PutSelText(GetBSTR(strText));
_bstr_t strSel2 = _FileClass->GetSelText();
if (!DataConvert::StringEqual(GetString(strSel2), strText))
{
ATLASSERT(FALSE);
}
int nSelStrat = _FileClass->GetSelStart();
_FileClass->PutFormatSelection(VARIANT_TRUE);
TitleSets rt2 = GetTitleStyle(_pRootElement, type);//默认正文
SetSelTextStyle(rt2);
_FileClass->PutFormatSelection(VARIANT_FALSE);
_FileClass->PutSelStart(nSelStrat + strText.GetLength() - 1);
_FileClass->PutSelLength(1);
_FileClass->Refresh();
return TRUE;
}
TitleSets CWordExportManger::GetTitleStyle( CXmlElement* pElement, StyleType type )
{
pElement = _pRootElement->GetChildElementAt(StyleTypeToText(type), FALSE);
TitleSets rt;
if (pElement == NULL)
{
ATLASSERT(FALSE);
return rt;
}
rt.Aligment = _tstoi(pElement->GetAttrValue(L"Aligment", L"0"));
rt.FontBold = _tstoi(pElement->GetAttrValue(L"FontBold", L"0"));
rt.BaseLine = _tstoi(pElement->GetAttrValue(L"BaseLine", L"0"));
rt.FontName = pElement->GetAttrValue(L"FontName", L"宋体");
rt.FontSize = _tstoi(pElement->GetAttrValue(L"FontSize", L"14"));
rt.FontUnderLine = _tstoi(pElement->GetAttrValue(L"FontUnderLine", L"0"));
rt.LineSpacing = _tstoi(pElement->GetAttrValue(L"LineSpacing", L"0"));
rt.LineSpacingT = _tstoi(pElement->GetAttrValue(L"LineSpacingT", L"0"));
rt.TextDirection = _tstoi(pElement->GetAttrValue(L"TextDirection", L"0"));
rt.FrameDistance = _tstoi(pElement->GetAttrValue(L"FrameDistance", L"0"));
rt.FrameLineWidth = _tstoi(pElement->GetAttrValue(L"FrameLineWidth", L"0"));
rt.FrameStyle = _tstoi(pElement->GetAttrValue(L"FrameStyle", L"0"));
rt.IndentB = _tstoi(pElement->GetAttrValue(L"IndentB", L"0"));
rt.IndentFL = _tstoi(pElement->GetAttrValue(L"IndentFL", L"0"));
rt.IndentL = _tstoi(pElement->GetAttrValue(L"IndentL", L"0"));
rt.IndentR = _tstoi(pElement->GetAttrValue(L"IndentR", L"0"));
rt.IndentT = _tstoi(pElement->GetAttrValue(L"IndentT", L"0"));
rt.Justification = _tstoi(pElement->GetAttrValue(L"Justification", L"0"));
rt.KeepLinesTogether = DataConvert:: Text2Bool(pElement->GetAttrValue(L"KeepLinesTogether", L"FALSE"));
rt.KeepWithNext = DataConvert:: Text2Bool(pElement->GetAttrValue(L"KeepWithNext", L"FALSE"));
rt.PageBreakBefore = DataConvert:: Text2Bool(pElement->GetAttrValue(L"PageBreakBefore", L"FALSE"));
rt.TabCurrent = _tstoi(pElement->GetAttrValue(L"TabCurrent", L"1"));
rt.TabPos = _tstoi(pElement->GetAttrValue(L"TabPos", L"0"));
rt.TabType = _tstoi(pElement->GetAttrValue(L"TabType", L"0"));
rt.WindowOrPhanLines = _tstoi(pElement->GetAttrValue(L"WindowOrPhanLines", L"1"));
return rt;
}
void CWordExportManger::SetSelTextStyle( TitleSets titleSets )
{
_FileClass->PutLineSpacing(titleSets.LineSpacing);
_FileClass->PutLineSpacingT(titleSets.LineSpacingT);
_FileClass->PutTextDirection((TextDirectionConstants)(titleSets.TextDirection));
_FileClass->PutFrameDistance(titleSets.FrameDistance);
_FileClass->PutFrameLineWidth(titleSets.FrameLineWidth);
_FileClass->PutFrameStyle(titleSets.FrameStyle);
_FileClass->PutIndentB(titleSets.IndentB);
_FileClass->PutIndentFL(titleSets.IndentFL);
_FileClass->PutIndentL(titleSets.IndentL);
_FileClass->PutIndentR(titleSets.IndentR);
_FileClass->PutIndentT(titleSets.IndentT);
_FileClass->PutJustification((JustificationConstants)titleSets.Justification);
_FileClass->PutKeepLinesTogether(titleSets.KeepLinesTogether ? VARIANT_TRUE: VARIANT_FALSE);
_FileClass->PutKeepWithNext(titleSets.KeepWithNext ? VARIANT_TRUE: VARIANT_FALSE);
_FileClass->PutPageBreakBefore(titleSets.PageBreakBefore ? VARIANT_TRUE: VARIANT_FALSE);
_FileClass->PutTabCurrent(titleSets.TabCurrent);
_FileClass->PutTabPos(titleSets.TabPos);
_FileClass->PutTabType(titleSets.TabType);
_FileClass->PutWidowOrphanLines(titleSets.WindowOrPhanLines);
_FileClass->PutAlignment(titleSets.Aligment);
_FileClass->PutFontBold(titleSets.FontBold);
_FileClass->PutBaseLine(titleSets.BaseLine);
_FileClass->PutFontName(GetBSTR(titleSets.FontName));
_FileClass->PutFontSize(titleSets.FontSize);
_FileClass->PutFontUnderline(titleSets.FontUnderLine);
}
int CWordExportManger::InsertImage( CString strFile, int TextPos, int Alignment, int PosX, int PosY , int ScaleX, int ScaleY, int TextFlow, ImageSets imSet )
{
int nImage = -1;
try
{
nImage = _FileClass->ImageInsert(GetBSTR(strFile),0, PosX, PosY, ScaleX, ScaleY, TextFlow, imSet.DistanceL, imSet.DistanceT, imSet.DistanceR, imSet.DistanceB);
}
catch(...)
{
}
return nImage;
}
void main()
{
try
{
_FileClass->Load(GetBSTR(strFilePath), 0, type, TRUE);
}
catch(...)
{
//RaiseError(L"不存在文件,创建文件");
PageSets set;
set.Set();
SetPageAligment(set);
_FileClass->Save(GetBSTR(strFilePath), 0, type, FALSE);
}
//通过Thread来通不断写入Text ---strResult就是取出的文本
_pWordManger->PutText(strResult + L"\n", StyleTextNormal);
//调用插入后 上面记录的样式是用Xml存储的。
_pWordManger->InsertImage(....)信息后崩溃。
}
Xml样式
<Document>
<标题1 Aligment="3" FontBold="1" BaseLine="0" FontName="宋体" FontSize="22" FontUnderLine="0" LineSpacing="241" LineSpacingT="1296" TextDirection="2" FrameDistance="0" FrameLineWidth="0" FrameStyle="32" IndentB="330" IndentFL="0" IndentL="0" IndentR="0" IndentT="340" Justification="1" KeepLinesTogether="True" KeepWithNext="True" PageBreakBefore="False" TabCurrent="1" TabPos="1134" TabType="1" WindowOrPhanLines="1" />
<标题2 Aligment="3" FontBold="1" BaseLine="0" FontName="宋体" FontSize="16" FontUnderLine="0" LineSpacing="173" LineSpacingT="0" TextDirection="2" FrameDistance="0" FrameLineWidth="0" FrameStyle="32" IndentB="-32768" IndentFL="0" IndentL="0" IndentR="0" IndentT="-32768" Justification="1" KeepLinesTogether="True" KeepWithNext="True" PageBreakBefore="False" TabCurrent="1" TabPos="1134" TabType="1" WindowOrPhanLines="1" />
<标题3 Aligment="3" FontBold="1" BaseLine="0" FontName="宋体" FontSize="16" FontUnderLine="0" LineSpacing="173" LineSpacingT="0" TextDirection="2" FrameDistance="0" FrameLineWidth="0" FrameStyle="32" IndentB="260" IndentFL="0" IndentL="0" IndentR="0" IndentT="260" Justification="1" KeepLinesTogether="True" KeepWithNext="True" PageBreakBefore="False" TabCurrent="1" TabPos="1134" TabType="1" WindowOrPhanLines="1" />
<正文 Aligment="0" FontBold="0" BaseLine="0" FontName="宋体" FontSize="11" FontUnderLine="0" LineSpacing="73" LineSpacingT="0" TextDirection="1" FrameDistance="1" FrameLineWidth="1" FrameStyle="16" IndentB="0" IndentFL="0" IndentL="0" IndentR="0" IndentT="0" Justification="2" KeepLinesTogether="False" KeepWithNext="False" PageBreakBefore="False" TabCurrent="3" TabPos="0" TabType="0" WindowOrPhanLines="0" />
</Document> |