Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Conditional printing

Hi,

I have an Excel worksheet that has some rows that sometimes do not need to
appear in a print out (for instance if a specific column has a "NO" in it). I
could perhaps make the text same color as background (is there a better
technique to not print that text?) but the rows in the printout are numbered
so I get discontinous numbering when some of the rows are indeed to be
excluded from printing.

Can someone provide some insight as to the best and simplest solution?
I really have very little experience with Excel although a lot with C#/C++...

--
Thanks in advance,

Juan Dent, M.Sc.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Conditional printing

Hey Juan,

the most simple solution that I can think of is hiding those rows for the
moment...

Rob

"Juan Dent" schreef in bericht
...
Hi,

I have an Excel worksheet that has some rows that sometimes do not need to
appear in a print out (for instance if a specific column has a "NO" in
it). I
could perhaps make the text same color as background (is there a better
technique to not print that text?) but the rows in the printout are
numbered
so I get discontinous numbering when some of the rows are indeed to be
excluded from printing.

Can someone provide some insight as to the best and simplest solution?
I really have very little experience with Excel although a lot with
C#/C++...

--
Thanks in advance,

Juan Dent, M.Sc.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Conditional printing

Hello Juan,

From your post, my understanding on this issue is: you want to print the
rows of a Excel worksheet satisfying certain conditions and appropriately
adjust the serial number. If I'm off base, please feel free to let me know.

Here are two approaches:
(The sample codes below is written in C#. To learn how to bind Office
automation servers with Visual C# .NET, please refer to the kb:
http://support.microsoft.com/kb/302902/)

Approach 1. Call Hidden = true for the rows to be filtered, and
appropriately adjust the numbering.
Step 1: Hide the rows and adjust the numbering: (please refer to the
following pseudo code)
int hiddenRowsCount = 0; // used to count the hidden rows
Excel.Worksheet sheet = (Excel.Worksheet)document.Worksheets[index];
for (int i = 1; i <= sheet.UsedRange.Rows.Count; i++) {
Excel.Range range = (Excel.Range)sheet.Rows[i, missing];
// judge whether the row should not be printed out.
if (/*the row should not be printed out*/) {
range.EntireRow.Hidden = true; // hide the entire row
hiddenRowsCount++;
} else {
// adjust the numbering according to the hiddenRowsCount
Excel.Range numberingCell = (Excel.Range)range.Cells[missing,
/*the numbering column*/];
numberingCell.Value2 =
int.Parse(numberingCell.Value2.ToString()) - hiddenRowsCount;
}
}

Step 2: Print the worksheet by calling PrintOut

Step 3: Recover the worksheet by calling Hidden=false and re-adjust the
numbering column:
int hiddenRowsCount = 0; // used to count the hidden rows
Excel.Worksheet sheet = (Excel.Worksheet)document.Worksheets[index];
for (int i = 1; i <= sheet.UsedRange.Rows.Count; i++) {
Excel.Range range = (Excel.Range)sheet.Rows[i, missing];
// judge whether the row should not be printed out.
if (/*the row is hidden*/ range.EntireRow.Hidden) {
range.EntireRow.Hidden = false; // hide the entire row
hiddenRowsCount++;
} else {
// adjust the numbering according to the hiddenRowsCount
Excel.Range numberingCell = (Excel.Range)range.Cells[missing,
/*the numbering column*/];
numberingCell.Value2 =
int.Parse(numberingCell.Value2.ToString()) + hiddenRowsCount;
}
}

Approach 2. If the data in the worksheet is not big, we can copy the data
to a new worksheet, iterate the rows and Delete the rows that should not be
printed out. Then we could call AutoFill to adjust the numbering column and
print the sheet out. Finally, we delete this worksheet.
Excel.Range range = sheet.get_Range("A1", "A2");
Excel.Range destination = sheet.get_Range("A1", "A33");
range.AutoFill(destination,
Microsoft.Office.Interop.Excel.XlAutoFillType.xlFi llDefault);

Please let me know if you have any other concerns, or need anything else.

Sincerely,
Jialiang Ge , remove 'online.')
Microsoft Online Community Support

==================================================
For MSDN subscribers whose posts are left unanswered, please check this
document: http://blogs.msdn.com/msdnts/pages/postingAlias.aspx

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express/Windows Mail, please make sure
you clear the check box "Tools/Options/Read: Get 300 headers at a time" to
see your reply promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Conditional printing

Hi Juan,

Would you mind letting me know the result of the suggestions? If you need
further assistance, feel free to let me know. I will be more than happy to
be of assistance.

Have a great day!

Sincerely,
Jialiang Ge , remove 'online.')
Microsoft Online Community Support

=================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from your issue.
=================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
conditional printing Conditional printing Excel Discussion (Misc queries) 4 September 15th 08 01:51 PM
Conditional Printing James[_4_] Excel Discussion (Misc queries) 1 July 24th 07 10:45 PM
Conditional Printing chris100[_56_] Excel Programming 3 February 11th 06 01:04 PM
Conditional Printing Josh Whitney Excel Programming 5 June 12th 04 12:26 AM
conditional printing raymondsum[_9_] Excel Programming 4 December 3rd 03 02:24 AM


All times are GMT +1. The time now is 12:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"