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

posted @ 2013-04-26 16:58  delphi中间件  阅读(2050)  评论(0编辑  收藏  举报