Click here to Skip to main content
15,887,267 members
Home / Discussions / C#
   

C#

 
GeneralRe: exception trying to insert a range to an Excelsheet Pin
Harry6662-Jul-09 13:58
Harry6662-Jul-09 13:58 
GeneralRe: exception trying to insert a range to an Excelsheet Pin
MumbleB2-Jul-09 22:14
MumbleB2-Jul-09 22:14 
GeneralRe: exception trying to insert a range to an Excelsheet Pin
Harry6664-Jul-09 0:57
Harry6664-Jul-09 0:57 
Generalstill trying to insert a range to an Excelsheet Pin
Harry6664-Jul-09 4:14
Harry6664-Jul-09 4:14 
GeneralRe: still trying to insert a range to an Excelsheet Pin
MumbleB4-Jul-09 8:31
MumbleB4-Jul-09 8:31 
GeneralRe: still trying to insert a range to an Excelsheet Pin
Harry6665-Jul-09 4:38
Harry6665-Jul-09 4:38 
GeneralUsing a makro Pin
Harry6665-Jul-09 6:04
Harry6665-Jul-09 6:04 
GeneralRe: still trying to insert a range to an Excelsheet Pin
MumbleB6-Jul-09 19:16
MumbleB6-Jul-09 19:16 
Hi Harry. I am happy you managed to find a solution by using a Macro. HOwever, the copy method I provided is correct and it works. I think I know why your method doesn't work. You needed to omit the following code and only select the starting cell where you want to start copying to.
1) you need to do the Insert to make the blank cells available.
2) Go to the sheet with the data that you want to copy.
3) Go back to the sheet you want to copy to and select the starting cell which I think from the above is "A11".
4) Now you do the paste special formats.

So, I would have written the code as below:
YOu have two past options, the first to copy only the formats and the other to copy both formats and data in the cells.

Below is to copy the data in the cells with the formats.
//Select the Range where you want to insert the data into
objRange = objSheet.get_Range("A6", "AK6");
objRange.Select();
//Insert Blank Line
objRange.Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
//Now go and select the data with the formatting that you want to copy.
objRange = objSheet.get_Range("A10", "Y10");
objRange.Select();
objRange.Copy(Type.Missing);
//Go back and select the first cell where you want to copy the data to
objRange = objSheet.get_Range("A6", Type.Missing);
objRange.Activate();
objRange.PasteSpecial(XlPasteType.xlPasteAll, XlPasteSpecialOperation.xlPasteSpecialOperationNone,
    false, false);

If you only want to copy the formats of the cells then you change the XlPasteType.xlPasteAll to XlPasteType.xlPasteFormats

When I did my first Excel App I had the same issues like you, pulled my hair out for a whole week. But, like I said, using the Macros to get an idea of what the code should look like helps. as for the false, false, that is just for "skipblanks" and "transpose" which is set to false unless you want to do those oporations.

Anyway, give the above a try, it should work. I tested it this morning and it works 100%

Excellence is doing ordinary things extraordinarily well.

GeneralRe: still trying to insert a range to an Excelsheet Pin
Harry6669-Jul-09 3:32
Harry6669-Jul-09 3:32 
QuestionDowloading file, web aplication and C# Pin
hoshyarD2-Jul-09 0:34
hoshyarD2-Jul-09 0:34 
AnswerRe: Dowloading file, web aplication and C# Pin
Manas Bhardwaj2-Jul-09 0:36
professionalManas Bhardwaj2-Jul-09 0:36 
QuestionVista/Win7 Gadget's Flyout. Pin
Supriya Tonape2-Jul-09 0:30
Supriya Tonape2-Jul-09 0:30 
AnswerRe: Vista/Win7 Gadget's Flyout. Pin
musefan2-Jul-09 1:58
musefan2-Jul-09 1:58 
GeneralRe: Vista/Win7 Gadget's Flyout. Pin
Supriya Tonape2-Jul-09 6:38
Supriya Tonape2-Jul-09 6:38 
QuestionIndex was out of range. Must be non-negative and less than the size of the collection Pin
haleemasher2-Jul-09 0:22
haleemasher2-Jul-09 0:22 
AnswerRe: Index was out of range. Must be non-negative and less than the size of the collection Pin
N a v a n e e t h2-Jul-09 0:28
N a v a n e e t h2-Jul-09 0:28 
GeneralRe: Index was out of range. Must be non-negative and less than the size of the collection Pin
haleemasher2-Jul-09 0:37
haleemasher2-Jul-09 0:37 
GeneralRe: Index was out of range. Must be non-negative and less than the size of the collection Pin
Luc Pattyn2-Jul-09 0:54
sitebuilderLuc Pattyn2-Jul-09 0:54 
QuestionNonSerialized property. Pin
johnnycastle2-Jul-09 0:19
johnnycastle2-Jul-09 0:19 
AnswerRe: NonSerialized property. Pin
Keith Barrow2-Jul-09 1:56
professionalKeith Barrow2-Jul-09 1:56 
GeneralRe: NonSerialized property. Pin
dojohansen2-Jul-09 2:21
dojohansen2-Jul-09 2:21 
AnswerRe: NonSerialized property. Pin
dojohansen2-Jul-09 2:04
dojohansen2-Jul-09 2:04 
AnswerRe: NonSerialized property. Pin
johnnycastle2-Jul-09 2:43
johnnycastle2-Jul-09 2:43 
QuestionUI Delay [modified] Pin
viciouskinid1-Jul-09 23:28
viciouskinid1-Jul-09 23:28 
AnswerRe: UI Delay Pin
Henry Minute2-Jul-09 0:02
Henry Minute2-Jul-09 0:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.