liaojunhua 发表于 2014-6-11 14:41:00

Tx Text Control Activex 怎么选择指定的行列?

比如 、

1234567
11223344556677


我想合并 5与6单元格,怎么选择这两列进行合并?
通过什么方法?TableCellSelect 只能从1开始?或者怎么更改选择开始的地方?

liaojunhua 发表于 2014-6-11 16:40:00

添加图片问题

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);
                //_FileClass->ImageInsert("D:\\1.bmp", 0, 3, 0, 0, 100, 100, 3, 2, 2, 2, 2);
        }
        catch(...)
        {
       
        }
       
        return nImage;
}

_FileClass为 创建的控件类。
如上两种方法都无法添加图片到Word文档中,而且引起软件卡死。
是否添加图片之前需要增加其他的操作?

在我之前的测试例子中直接添加 _FileClass->ImageInsert("D:\\1.bmp", 0, 3, 0, 0, 100, 100, 3, 2, 2, 2, 2);
是可以保存并且显示出来的。而且很快。

iceman 发表于 2014-6-11 18:12:00

回复 2楼liaojunhua的帖子

你好,
你的问题我们已经查收,明天回复给你。

liaojunhua 发表于 2014-6-12 10:08:00

你好。通过TextControl COM创建的指针完成大批量的文本插入后插入图片会导致程序假死,软件主进程未结束,但是分析线程提前退出。
但是目前出现一个问题,我通过线程插入文本,但是在遇到插入图片的时候无法插入,能不能查询到设置了什么导致无法插入图片呢?
我在创建新的Word的文档时是可以插入图片的。
这一点让我很疑惑。
是否需要提供部分代码?帮助分析一下呢?

iceman 发表于 2014-6-12 16:58:00

回复 1楼liaojunhua的帖子

1#中问题方法如下:

Private Sub Command1_Click()
    Me.TXTextControl1.TableInsert 2, 7, -1, 11
   
End Sub

Private Sub Command2_Click()
   
    Me.TXTextControl1.SelStart = Me.TXTextControl1.TableCellStart(11, 1, 5) - 1
   
    Me.TXTextControl1.SelLength = 1
    Me.TXTextControl1.TableMergeCells
      
End Sub

iceman 发表于 2014-6-12 17:00:00

回复 4楼liaojunhua的帖子

4# 中的问题能否请你提供一个 Demo 来重现问题?

liaojunhua 发表于 2014-6-13 08:51:00

是不是不支持纵向合并这样?demo我看看怎么提取出来

liaojunhua 发表于 2014-6-13 10:48:00

您好,还想请问一个问题,Table能否提供一种Xml配置或者使用一种外部定义的数据结构来合并?

liaojunhua 发表于 2014-6-13 15:09:00

上面的问题如果使用C++ActiveX控件需要进行以下操作才能将指定行合并。
需要先进行
TxControl->PutSelStar(TxControl->GetTableCellStar(10, 1, 5));
TxControl->PutSelLength(1);
这时候需要再设置一次,否则SelStar无法保存进去。
TxControl->PutSelStar(TxControl->GetTableCellStar(10, 1,5) - 1);
TXControl->PutSelLength(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->PutPageWidth(pageSets.width);//标准A4
        _FileClass->PutPageMarginL(pageSets.MarinLeft);
        _FileClass->PutPageMarginR(pageSets.MarinRight);
        _FileClass->PutPageMarginT(pageSets.MarinTop);
        _FileClass->PutPageMarginB(pageSets.MarinBottom);
        _FileClass->PutPageHeight(pageSets.heigth);//标准A4
}

BOOL CWordExportManger::PutSelText( CString strText, StyleTypetype)
{
        _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>

iceman 发表于 2014-6-13 17:26:00

回复 9楼liaojunhua的帖子

8# 中的问题“Table能否提供一种Xml配置或者使用一种外部定义的数据结构来合并”,请问 XML 文件的作用是什么?存储 table 的合并信息吗?

9# 中是否为 C++ 代码,能否发个源程序上来查看?
页: [1] 2
查看完整版本: Tx Text Control Activex 怎么选择指定的行列?