Как через DDE добавить к клетке Excel примечание (Note)
Задача через именно через DDE (с файлом активно работает старое приложение по DDE , а нужно оперативно вносить изменения и добавлять примечания к ячейкам, OLE при таком варианте уходит в ступор из-за ошибки совместного доступа ) добавить или изменить, если существует Примечание к ячейке Экселя. Excel - версия Excel2003
Через OLE могу решить без проблем но как писал выше OLE - не проходит.
| Код | newComment:= 'Ошибка обработки данных в ячейке |'+TimeToStr(Time))+ Chr(10); Wsheet1.Cells[LRow,LCol].NoteText(Wsheet1.Cells[LRow,LCol].NoteText+newComment);
|
А вот по DDE не получается. Вроде есть метод TDdeClientConv.ExecuteMacro, но заставить его работать не получаеться.
| Код | procedure TForm2.Button5Click(Sender: TObject); var tempComm:string; begin {Добавляем примечание} if DdeClientConv1.SetLink('EXCEL', 'D:\[test001.xls]L002') and DdeClientConv1.OpenLink then begin try tempComm:='[NOTE("Проверочный комментарий","R2C3")]'; // формируем макрос if DdeClientConv1.ExecuteMacro(PChar(tempComm), false) then Memo2.Lines.Add('исполненно' ) else Memo2.Lines.Add('проблеммы' ) ; finally DdeClientConv1.CloseLink; end; end; end;
|
Если посылаю "пустой" макрос,
| Код | tempComm:='[NOTE()]';
|
то к активной ячейке листа добавляется Примечание (пустое) открытое для редактирования. Хотя вроде это команда удаления примечания. А вот попытка занести в конкретную (а не активную) ячейку комментарий, не удается. Макрос вроде исполняется вернув TRUE , но ячейка не меняется.
Помогите пожалуйста советом.
PS: макрос взял из Excel Macro Function Help
| Код | Equivalent to choosing the Note command from the Insert menu. Creates a note or replaces characters in a note. Use NOTE to create a cell note or to replace a specified number of characters with other text.
Syntax
NOTE(add_text, cell_ref, start_char, num_chars) NOTE?( ) Add_text is text of up to 255 characters you want to add to a note. Add_text must be enclosed in quotation marks.
If add_text is omitted, it is assumed to be "" (empty text) unless the note includes sound. If a note contains sound and you omit add_text, Microsoft Excel deletes the entire note, but if you explicitly specify empty text, Microsoft Excel deletes only the text, not the sound. To erase only the sound, use the SOUND.NOTE function.
Cell_ref is the cell to which you want to add the note text. If cell_ref is omitted, add_text is added to the active cell's note. Start_char is the number of the character at which you want add_text to be added. If start_char is omitted, it is assumed to be 1. If there is no existing note, start_char is ignored. Num_chars is the number of characters that you want to replace in the note. If num_chars is omitted, it is assumed to be equal to the length of the note.
Remarks
NOTE returns the number of the last character entered in the cell note. This is useful if you want to know how many characters are in the text string so it can be manipulated with other functions such as RIGHT, LEFT, and MID. The dialog-box form of this function, NOTE?, takes no arguments. NOTE() deletes the note attached to the active cell.
To find out if a cell has a note attached to it, use GET.CELL.
|
|