![]() |
| | #1 |
| CS Author and Instructor Join Date: Sep 2002
Posts: 511
| Adding Line numbers in Word Currently on another project-will answer those AP questions later this week. Have a problem. In VS .NET I can add line numbers to the code, but when I copy and paste this code with line numbers into Word, the line numbers are not there. How can I keep these line numbers to stay in Word? PS. I know you can suppress line numbers/add line numbers in Word itself. I tried it via help. It is not easy to do, especially with multiple places in the document to add line numbers to. Thoughts appreciated. Also, will let you know about the little project I am working on at a later date. Mr. C.
__________________ Mr. C: Author and Instructor |
| Mister C is offline |
| | #2 |
| 5|-|1+|-|34|) Join Date: Aug 2001
Posts: 4,429
| Try pasting it into notepad or wordpad first. Those programs won't try to manipulate your text before showing it to you. |
| ober is offline |
| | #3 |
| Registered User Join Date: Jun 2004
Posts: 1
| Hello, this post was made with a 3rd party application for testing reasons. |
| anon29 is offline |
| | #4 |
| & the hat of GPL slaying Join Date: Sep 2001
Posts: 5,732
| Are you sure that when you copy from VS.NET it is actually copying the line numbers? To me it would make more sense for the line numbers to be added by the IDE and not really be text. But of course I don't have VS.NET so I don't know for sure |
| Thantos is offline |
| | #5 | |
| CS Author and Instructor Join Date: Sep 2002
Posts: 511
| Quote:
__________________ Mr. C: Author and Instructor | |
| Mister C is offline |
| | #6 |
| & the hat of GPL slaying Join Date: Sep 2001
Posts: 5,732
| Does VS.NET have a print to file option? And could word open that file? Just throw out ideas |
| Thantos is offline |
| | #7 |
| Code Goddess Join Date: Sep 2001
Posts: 9,664
| >I guess I will have to add the line numbers in word. And you call yourself a programmer. Write a script to do it for you. ![]() Code: #!/usr/bin/perl
#
# nladd
# Add line numbers to a text file
use warnings;
use strict;
open LINES_FILE, ">lines" or die;
my $line_count = 1;
while (<ARGV>) {
print LINES_FILE "$line_count $_";
$line_count++;
}
__________________ My best code is written with the delete key. |
| Prelude is offline |
| | #8 |
| 5|-|1+|-|34|) Join Date: Aug 2001
Posts: 4,429
| Wouldn't that be techically screwed up if a certain line wraps? Unless when you copy it from the IDE, it carries along any new line characters. |
| ober is offline |
| | #9 |
| l'Anziano Join Date: Aug 2001
Posts: 2,630
| or with PHP: Code: <?
$a_lines = file("sourcefile.cpp");
$line_count = count($a_lines);
$fp = fopen('sourcefile.cpp', 'w');
for ( $i = 0; $i < $line_count; $i++ )
{
$content = "$i\t$a_lines[$i]";
fwrite($fp, $content);
}
fclose($fp);
?>
|
| DavidP is offline |
| | #10 |
| Code Goddess Join Date: Sep 2001
Posts: 9,664
| >Wouldn't that be techically screwed up if a certain line wraps? Not enough to warrant a fix for the simple use the script was designed for.
__________________ My best code is written with the delete key. |
| Prelude is offline |
| | #11 |
| and the hat of Jobseeking Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,700
| @Mister C Why don't you write yourself a nice little VBA macro in word, which you pass to it the name of the .c source file you want to quote from, and the range of lines you want to import, and it does all the hard work for you. Even better, why not add magic comments to the 'C' source code so you don't have to refer to line numbers at all, but can refer instead to named sections of the code. |
| Salem is offline |
| | #12 |
| Crazy Fool Join Date: Jan 2003 Location: Canada
Posts: 2,596
| first get a real operating system , then do thisCode: grep -n .\* in-file > out-file
__________________ jeff.bagu.org - Terrain rendering and other random stuff |
| Perspective is offline |
| | #13 |
| Registered User Join Date: Mar 2003 Location: Louisiana
Posts: 926
| behold the many powers of grep . Don't you just love linux? Last edited by linuxdude; 06-23-2004 at 10:19 PM. |
| linuxdude is offline |
| | #14 |
| Yes, my avatar is stolen Join Date: Dec 2002
Posts: 2,544
| Here is the result of some procrastination: Code: Sub ImportCode()
Dim xlApp As Object, fso As Object, tstream As Object
Dim nStart As Integer, nEnd As Integer, nLine As Integer
Dim strLine As String
Set xlApp = CreateObject("Excel.Application")
strFile = xlApp.GetOpenFilename("C/C++ Source Files (*.c; *.cpp),*.c;*.cpp")
xlApp.Quit
If (strFile = False) Then Exit Sub
nStart = CInt(InputBox("Please enter the start line.", "Start", 0))
nEnd = CInt(InputBox("Please enter the end line.", "End", 999))
Set fso = CreateObject("Scripting.FileSystemObject")
Set tstream = fso.OpenTextFile(strFile)
While (Not tstream.AtEndOfStream)
strLine = tstream.ReadLine
If (nLine >= nStart And nLine <= nEnd) Then
Selection.Font.Color = wdColorBlueGray
Selection.TypeText Format(nLine, "#000")
Selection.Font.Color = wdColorAutomatic
Selection.TypeText " " & strLine & vbCrLf
End If
nLine = nLine + 1
Wend
End Sub
|
| anonytmouse is offline |
| | #15 | |
| erstwhile Join Date: Jan 2002
Posts: 2,223
| Quote:
__________________ CProgramming FAQ Caution: this person may be a carrier of the misinformation virus. | |
| Ken Fitlike is offline |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Seg Fault in Compare Function | tytelizgal | C Programming | 1 | 10-25-2008 03:06 PM |
| brace-enclosed error | jdc18 | C++ Programming | 53 | 05-03-2007 05:49 PM |
| adding odd numbers only | CheyenneWay | C++ Programming | 12 | 05-06-2004 12:22 AM |
| the definition of a mathematical "average" or "mean" | DavidP | A Brief History of Cprogramming.com | 7 | 12-03-2002 11:15 AM |
| Line Numbers in VI and/or Visual C++ :: C++ | kuphryn | C++ Programming | 2 | 02-10-2002 10:54 PM |