We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Export Text with Comment to Clipboard

Hello, I tried to export a grid to Clipboard with XML Format. The MOST IMPORTENT thing is, some cells of the grid are with ToolTipText, which I want to export as Comment. my Code looks like this:

private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.C)
{
ExcelEngine lExcelEngine = new ExcelEngine();
IApplication lApplication = lExcelEngine.Excel;
lApplication.DefaultVersion = ExcelVersion.Excel2010;

IWorkbook lWorkbook = lApplication.Workbooks.Create(1);

IWorksheet lWorksheet = lWorkbook.Worksheets[0];
Selected lSelected = this.ultraGrid1.Selected;

for (int i = 0; i < lSelected.Cells.Count; i++)
{
UltraGridCell lUltraGridCell = lSelected.Cells[i];
IRange lRange = lWorksheet.Range[lUltraGridCell.Row.Index + 1, lUltraGridCell.Column.Index + 1];
lRange.Value = lUltraGridCell.Text;
if (!string.IsNullOrEmpty(lUltraGridCell.ToolTipText))
{
ICommentShape lCommentShape = lRange.AddComment();
lCommentShape.Text = lUltraGridCell.ToolTipText;
}
}

//Solution 1: Comments are not included
//lWorksheet.CopyToClipboard();

//Solution 2: Comments are included
MemoryStream lDataObject = new MemoryStream();
//Bug: System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
lWorkbook.SaveAsXml(lDataObject, ExcelXmlSaveType.MSExcel);
Clipboard.SetData("XML Spreadsheet", lDataObject);
}
}

But I get an Exception:
bei System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
bei System.Collections.Generic.SortedList`2.GetKey(Int32 index)
bei System.Collections.Generic.SortedList`2.KeyList.get_Item(Int32 index)
bei Syncfusion.XlsIO.Implementation.XmlSerialization.WorkbookXmlSerializator.SerializeRichText(XmlWriter writer, TextWithFormat rtf, String text, FontsCollection fonts, IFont defFont)
bei Syncfusion.XlsIO.Implementation.XmlSerialization.WorkbookXmlSerializator.SerializeComment(XmlWriter writer, IComment comment, FontsCollection fonts, IFont defFont)
bei Syncfusion.XlsIO.Implementation.XmlSerialization.WorkbookXmlSerializator.SerializeCell(XmlWriter writer, WorksheetImpl sheet, Int32 iRowIndex)
bei Syncfusion.XlsIO.Implementation.XmlSerialization.WorkbookXmlSerializator.SerializeRows(XmlWriter writer, WorksheetImpl sheet)
bei Syncfusion.XlsIO.Implementation.XmlSerialization.WorkbookXmlSerializator.SerializeTable(XmlWriter writer, WorksheetImpl sheet)
bei Syncfusion.XlsIO.Implementation.XmlSerialization.WorkbookXmlSerializator.SerializeWorksheet(XmlWriter writer, WorksheetImpl sheet)
bei Syncfusion.XlsIO.Implementation.XmlSerialization.WorkbookXmlSerializator.SerializeWorksheets(XmlWriter writer, IWorksheets worksheets)
bei Syncfusion.XlsIO.Implementation.XmlSerialization.WorkbookXmlSerializator.SerializeWorkbook(XmlWriter writer, IWorkbook book)
bei Syncfusion.XlsIO.Implementation.XmlSerialization.WorkbookXmlSerializator.Serialize(XmlWriter writer, IWorkbook book)
bei Syncfusion.XlsIO.Implementation.WorkbookImpl.SaveAsXml(XmlWriter writer, ExcelXmlSaveType saveType)
bei Syncfusion.XlsIO.Implementation.WorkbookImpl.SaveAsXml(Stream stream, ExcelXmlSaveType saveType)
bei ClipboardTester.Form1.ultraGrid1_KeyDown(Object sender, KeyEventArgs e) in D:\Development\Travis\miscellaneous\ClipboardTester\ClipboardTester\Form1.cs:Zeile 76.
bei System.Windows.Forms.Control.OnKeyDown(KeyEventArgs e)
bei Infragistics.Win.UltraControlBase.OnKeyDown(KeyEventArgs e)
bei System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
bei System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
bei System.Windows.Forms.Control.WmKeyChar(Message& m)
bei System.Windows.Forms.Control.WndProc(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
bei System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

I have no idea and don't know how can i resolve this problem. The most important thing of this program is, the comments must be exported into Clipboard, so that when I paste the data in the clipboard to Excel, the comments will also be pasted.



5 Replies

SR Sridhar Syncfusion Team September 8, 2011 01:32 PM UTC

Hi Zhaojian,

Thank you very much for using Syncfusion products.

In your previous post we could see you are using the UltraGrid Control to export in in to the excel document. We have tried to download the prodcut at our side and we are unable use it at our side. We could not find the download link for the same.
So we have created the XlsIO sample at our side for the above requirement and updated here for your reference. We are using 9.3.0.61 version and let us know the essential studio version you are using at your side.

Please try the sample at your side and let us know if these helps you. If you still face the issue, Please get back to us with the sample to proceed further.

Please let us know if you require any further clarifications.

Thanks,
Sridhar.S



CommentsToClipboard_5e5a27cc.zip


ZL Zhaojian Li September 8, 2011 02:43 PM UTC

Hello, Thank you for your answer, I have tried your Example, it work at first. But after that, I add one line to it, it shows the same error:

IRange range = sheet.Range["C6"];
>>> range.Text = "QQ";

ICommentShape cShape = range.AddComment();
cShape.Name = "comment";
cShape.Text = "Sycnfusion-test-Xml comment";

That means Rang.Text must be empty or the cShape.Text must be empty.



ZL Zhaojian Li September 8, 2011 02:46 PM UTC

But I should export the cell which is not empty and the comment also with content.



SR Sridhar Syncfusion Team September 9, 2011 02:11 PM UTC

Hi Zhaojian,

Thanks for the update.

We are able to reproduce the reported issue at our side and suspect this could be a defect.

So we request you to open a new direct-trac incident with a simple issue reproducing sample for further follow up on this issue.

Direct-Trac Link:
https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents

Please, let us know if you require any further clarifications.

Thanks,
Sridhar.S




AN Andre replied to Sridhar February 28, 2018 04:40 AM UTC

Hi Zhaojian,

Thanks for the update.

We are able to reproduce the reported issue at our side and suspect this could be a defect.

So we request you to open a new direct-trac incident with a simple issue reproducing sample for further follow up on this issue.

Direct-Trac Link:
https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents

Please, let us know if you require any further clarifications.

Thanks,
Sridhar.S



Community License

Loader.
Live Chat Icon For mobile
Up arrow icon