EDN Admin
Well-known member
Hi,
I am working on an Excel Addin, but this problem is in general to C# and i chose this forum.
I have a scenario where user can select a set of cells from an Excel worksheet and then open a new workbook and then tries to paste the cells using the option "PasteSpecial". This should normally work fine. But in my case i have clear some cells in the workbook
when the user tries to take the focus away from a workbook. When i try to do this, it clears of the content from the clipboard which is normal Excel behavior. So in order to avoid loss of data from clipboard, i decided to copy the data from clipboard and then
do the clearing of cells and then trying to copy the data back to clipboard.
I did this using the following code snippet.
<div style="color:black; background-color:white
<pre>IDataObject data = <span style="color:blue new DataObject();
<span style="color:blue try
{
<span style="color:blue foreach (<span style="color:blue string contentType <span style="color:blue in Clipboard.GetDataObject().GetFormats())
{
<span style="color:blue if (contentType == <span style="color:#a31515 "EnhancedMetafile")
{
}
<span style="color:blue else
{
data.SetData(contentType, Clipboard.GetDataObject().GetData(contentType));
}
}
}
<span style="color:blue catch (Exception ex)
{
Utility.Factory.CustomLoggerFactory.GetLogger().WriteLine(<span style="color:#a31515 "Error on copying data to clipboard: " + ex.Message);
}
<span style="color:green //Do some actions.
Clipboard.SetDataObject(data);
[/code]
<a title="Image http://www.lazypic.com/images/59PasteSpecialIssue.jpg" target="_blank http://www.lazypic.com/images/59PasteSpecialIssue.jpg
In the attached Image, i expect the user to see the second option whereas the user is now seeing the first option when the above code gets executed.
How should i change the above code for the PasteSpecial to show the second option.
Any help is appreciated.
Thanks,
Shail
<br/>
<br/>
<br/>
<br/>
View the full article
I am working on an Excel Addin, but this problem is in general to C# and i chose this forum.
I have a scenario where user can select a set of cells from an Excel worksheet and then open a new workbook and then tries to paste the cells using the option "PasteSpecial". This should normally work fine. But in my case i have clear some cells in the workbook
when the user tries to take the focus away from a workbook. When i try to do this, it clears of the content from the clipboard which is normal Excel behavior. So in order to avoid loss of data from clipboard, i decided to copy the data from clipboard and then
do the clearing of cells and then trying to copy the data back to clipboard.
I did this using the following code snippet.
<div style="color:black; background-color:white
<pre>IDataObject data = <span style="color:blue new DataObject();
<span style="color:blue try
{
<span style="color:blue foreach (<span style="color:blue string contentType <span style="color:blue in Clipboard.GetDataObject().GetFormats())
{
<span style="color:blue if (contentType == <span style="color:#a31515 "EnhancedMetafile")
{
}
<span style="color:blue else
{
data.SetData(contentType, Clipboard.GetDataObject().GetData(contentType));
}
}
}
<span style="color:blue catch (Exception ex)
{
Utility.Factory.CustomLoggerFactory.GetLogger().WriteLine(<span style="color:#a31515 "Error on copying data to clipboard: " + ex.Message);
}
<span style="color:green //Do some actions.
Clipboard.SetDataObject(data);
[/code]
<a title="Image http://www.lazypic.com/images/59PasteSpecialIssue.jpg" target="_blank http://www.lazypic.com/images/59PasteSpecialIssue.jpg
In the attached Image, i expect the user to see the second option whereas the user is now seeing the first option when the above code gets executed.
How should i change the above code for the PasteSpecial to show the second option.
Any help is appreciated.
Thanks,
Shail
<br/>
<br/>
<br/>
<br/>
View the full article