zoukankan      html  css  js  c++  java
  • cxRichEdit

    procedure TFrmAnnouncement.SetStoragerText;
    var
    strStoragerText, strKeyWord: string;
    tmpList: TStringList;
    LenText, I, j, K: Integer;
    curRow: TPoint;
    tmpStream: TStream;
    begin
    strStoragerText := cdsMain.FieldByName('StoragerText').AsString;
    LenText := Length(strStoragerText); // 长度
    tmpStream := TMemoryStream.Create;
    try
    if Pos('0x', strStoragerText) = 1 then
    begin
    strStoragerText := Copy(strStoragerText, 3, LenText - 2);
    HexStrToStream(strStoragerText, tmpStream);
    tmpStream.Seek(0, soFromBeginning);
    mmoStoragerText.Lines.LoadFromStream(tmpStream);
    end
    else
    begin
    mmoStoragerText.Text := strStoragerText;
    end;
    LenText := Length(mmoStoragerText.Text); // 长度
    finally
    FreeAndNil(tmpStream);
    end;
    curRow.X := 0;
    curRow.Y := 0;
    mmoStoragerText.CaretPos := curRow;
    mmoStoragerText.SetFocus;
    // 正文高亮keywords
    tmpList := TStringList.Create;
    try
    tmpList.Delimiter := ' ';
    tmpList.CommaText := FKeyWords;
    for I := 0 to tmpList.Count - 1 do
    begin
    strKeyWord := tmpList.Strings[I];
    if strKeyWord <> '' then
    begin
    j := 0;
    K := 0;
    repeat
    K := mmoStoragerText.FindTexT(strKeyWord, j, LenText,
    [stMatchCase], True);
    if (K >= 0) then
    begin
    with mmoStoragerText.Properties do
    begin
    mmoStoragerText.SelStart := K;
    mmoStoragerText.SelLength := Length(strKeyWord);
    mmoStoragerText.SelAttributes.Color := clBlue;
    mmoStoragerText.SelAttributes.Style :=
    mmoStoragerText.SelAttributes.Style + [fsBold];
    end;
    // 定位到第一个高亮词语
    if (curRow.X = 0) and (curRow.Y = 0) then
    begin
    curRow.X := mmoStoragerText.CaretPos.X;
    curRow.Y := mmoStoragerText.CaretPos.Y;
    end
    else if curRow.Y > mmoStoragerText.CaretPos.Y then
    begin
    curRow.X := mmoStoragerText.CaretPos.X;
    curRow.Y := mmoStoragerText.CaretPos.Y;
    end;
    end;
    j := K + 1;
    if j > LenText then
    Break;
    until K < 0;
    end;
    end; // 结束循环
    // 定位到第一个高亮词语
    mmoStoragerText.CaretPos := curRow;
    finally
    FreeAndNil(tmpList);
    end;
    end;

    OleInitialize(nil);
    // 打开工作簿
    FExcel.Workbooks.Open(OpenDialog1.filename);
    // 取工作表数量
    SheetCount := FExcel.Worksheets.Count;
    // 遍历工作表
    for i := 1 to SheetCount do
    begin
    // 当前的工作表
    ActiveSheet := FExcel.Worksheets[i];
    ActiveSheet.Activate;
    // 当前工作表的行数
    RowCount := ActiveSheet.usedRange.Rows.Count;
    // 当前工作表的列数
    ColCount := ActiveSheet.usedRange.columns.Count;
    case ComboBox1.ItemIndex of
    0: // 产品资料
    begin
    // 遍历列 一列对应一个产品
    for iCol := 2 to ColCount do
    begin
    if Trim(ActiveSheet.cells[BeginLineNO, iCol]) <> '' then // 标题有值
    begin
    cxRichEdit1.Clear;
    ImageCount := ActiveSheet.Shapes.Count;
    if ImageCount > 0 then
    begin
    // 拷贝图片
    try
    ActiveShape := ActiveSheet.Shapes.Item(iCol - 1);
    except
    end;
    Clipboard.Clear;
    ActiveShape.Copy;
    cxRichEdit1.PasteFromClipboard;
    ActiveShape := UnAssigned;
    end;
    // 知识编号 GUID 一个知识必须有一个知识编号
    recZhiShi.StoragerID := GetGUID;
    // 知识标题
    recZhiShi.Caption := Trim(ActiveSheet.cells[BeginLineNO, iCol]);
    // 遍历行 拼成产品资料明细
    for iRow := BeginLineNO to RowCount do
    begin
    if Trim(ActiveSheet.cells[iRow, 1]) <> '' then
    begin
    s := Trim(ActiveSheet.cells[iRow, 1].Value) + ':' +
    Trim(ActiveSheet.cells[iRow, iCol].Value);
    cxRichEdit1.Lines.Add(s);
    end;
    end;
    Save;
    end;
    end;
    end;
    1: // 维修
    begin
    // 遍历行 一行对应一个故障
    for iRow := BeginLineNO + 1 to RowCount do
    begin
    cxRichEdit1.Lines.Clear;
    if Trim(ActiveSheet.cells[iRow, 1]) <> '' then
    begin
    recZhiShi.StoragerID := GetGUID;
    recZhiShi.Caption := Trim(ActiveSheet.cells[iRow, 1]) + '--' +
    Trim(ActiveSheet.cells[iRow, 2]);
    cxRichEdit1.Lines.Add(Trim(ActiveSheet.cells[iRow, 1]));
    cxRichEdit1.Lines.Add('【故障描述】:'+Trim(ActiveSheet.cells[iRow, 2]));
    cxRichEdit1.Lines.Add('【排除方法】:'+Trim(ActiveSheet.cells[iRow, 3]));
    cxRichEdit1.Lines.Add('【适用型号】');
    cxRichEdit1.Lines.Add(ActiveSheet.cells[iRow, 4]);
    end;
    Save;
    end;
    end;
    end;
    // 释放Excel对象
    ActiveSheet := UnAssigned;
    OleUninitialize;
    end;

    StreamMode 全部设为FALSE, ALLOWOBJECT=TRUE

  • 相关阅读:
    剑指OFFER----面试题17- 打印从1到最大的n位数
    剑指OFFER----面试题16. 数值的整数次方
    剑指OFFER----面试题15. 二进制中1的个数
    剑指OFFER----面试题14- II. 剪绳子II
    07 多层if判断
    08 while循环
    06 if 流程控制
    03 身份运算符、逻辑运算符
    04 位运算符、运算符优先级
    02 赋值运算符、成员运算符
  • 原文地址:https://www.cnblogs.com/hnxxcxg/p/3045226.html
Copyright © 2011-2022 走看看