Solved

Creating word report using RTF document Loose formating in vbscript

Posted on 2009-04-11
12
752 Views
Last Modified: 2013-11-10
we are creating the word document(report) using template file .rtf file. initially we do define our template in the .rtf file then at run time we do replace its constant using vb script. everything work fine except formatting, we want certain columns to be in bold.

Is there any way to achieve this?
<%@ Language=VBScript %>

<%'option explicit%>

<!-- METADATA NAME="Microsoft ActiveX Data Objects 2.5 Library" TYPE="TypeLib" UUID="{00000205-0000-0010-8000-00AA006D2EA4}" -->

<!--#include file="../includes/connection.asp" -->

<!--#include file="../includes/commonfunctions.asp" -->

<!-- #include file="ReportFunctions.asp" -->
 

<%

'ContentType = "application/msword"

'Response.AddHeader "Content-Disposition", "attachment; filename=" & FileName 

'Response.Charset = "UTF-8"

'Response.ContentType = ContentType
 

StartDate = FormatDateSQL(Request("startdt"))

Enddate = FormatDateSQL(Request("enddt"))

GroupID = Request("group")

GroupName = request("GroupName")

'Issue = Request("Issue")
 

Dim cnn,fso,act,filename,filename1

Const ForReading = 1, ForWriting = 2, ForAppending = 3

Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

set fso = server.CreateObject("scripting.filesystemobject")	

filename=Server.MapPath("WordFormat/FullProduction.rtf")

filename1=Server.MapPath("WordFormat/FullProduction.doc")

Dim readfile, writefile

Set readfile=fso.GetFile(filename)

fso.CreateTextFile(filename1)

filename2= "WordFormat/FullProduction.doc"
 

Set writefile=fso.GetFile(filename1)

Dim Textread,Textwrite
 

Set Textread = readfile.OpenAsTextStream(ForReading, TristateUseDefault)

Set TextWrite= writefile.OpenAsTextStream(ForWriting, TristateUseDefault)
 

Dim iPos1, iPos2, PreData, PostData, LoopData

Dim Line, PageData
 

PageData = ""

Do While Not TextRead.AtEndOfStream

    Line = TextRead.readline

    'TextWrite.write Line

    PageData = PageData & Line

Loop
 

'PageData = "This is a test. LOOP_BEGINThis is inside loopLOOP_ENDloop got ended."

'Response.Write PageData & "<br />"

iPos1 = InStr(PageData,"LOOP_BEGIN") - 1

iPos2 = InStr(PageData,"LOOP_END") - 1

PreData = Left(PageData, iPos1)

LoopData = Mid(PageData, iPos1, iPos2 - iPos1 + 1)

PostData = Right(PageData, Len(PageData) - iPos2)
 

PreData = Replace(PreData, "xx/xx/xx", Request("startdt"))

PreData = Replace(PreData, "yy/yy/yy", Request("enddt"))

PreData = Replace(PreData, "Group_Name", GroupName)

LoopData = Replace(LoopData, "LOOP_BEGIN", "S_No")

LoopData1 = Replace(LoopData, "LOOP_BEGIN", "S_No")

PostData = Replace(PostData, "LOOP_END", "S_No")
 

Dim rsReport, iCount, Ms_Num, DoiField, Article_No, ColourField, TypeField, MonoFig

'set rsReport = GetArtworkReportData(jid, Volume, Issue)

set rsReport = GetFulProductionReportData(GroupID, StartDate, Enddate)

iCount = 0

'Response.Write "<br />Chet="

'Response.Write "<br />Count=" & rsReport.RecordCount

RCount = rsReport.RecordCount

'Response.End

Textwrite.write PreData

while not rsReport.EOF

    iCount = iCount + 1

   

    if(journal="")then

		journal = rsReport.Fields(0).Value

	end if
 

    volume = rsReport.Fields(1).Value

    issue = rsReport.Fields(2).Value

    I_ED10_S = ChangeDateFormat(rsReport.Fields(3).Value)

    'I_ED10_S = ChangeDateFormat(I_ED10_S)

    if I_ED10_S = "30/12/1899" or isnull(I_ED10_S) then I_ED10_S = "" end if

   

	If journal = rsReport.Fields(0).Value then 

		Total_Schd_Ed_Pages = Total_Schd_Ed_Pages + Schd_Ed_Pages

		

	else

		journal = rsReport.Fields(0).Value

		Line = LoopData

		Line = Replace(Line,"S_No","")

		

		Textwrite.write Line

		

    	Total_Schd_Ed_Pages = Schd_Ed_Pages

		

	end if

	

	Line = LoopData

	Line = Replace(Line,"S_No",journal)

	

	Textwrite.write Line

	If iCount = RCount Then

        LoopData = PostData

        Line = LoopData

		Line = Replace(Line,"S_No","")

		

		Textwrite.write Line

    End If

	

    rsReport.MoveNext

wend

'set PostData =  SetLine(iCount, PostData)

Textwrite.write Line 
 

'Response.End

'TextWrite.writeline PageData

set TextRead=nothing

set TextWrite=nothing

set fso=nothing

DownloadReport(server.MapPath(filename2))

%>

Open in new window

0
Comment
Question by:NishantGiri
  • 5
  • 5
12 Comments
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 500 total points
ID: 24141613
Creating RTF files isn't my expertise but it seems you may already have all that.  Do you just need the code to turn bold on/off in RTF?  If so it is \b (bold on) and \b0 (bold off).
Let me know how that helps or if I have misunderstood what you need.
bol
0
 

Author Comment

by:NishantGiri
ID: 24165054
Hi b0lsc0tt,

Yes You are right. I just want to make character in bold, I have tried \b and \b0 but couldn't get the success, When I open the word document nothing came in bold letter. Is there any other way to resolve this?

Thank You

Regards,
Nishant Giri.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24165256
Can you show me the resulting rtf file's "text"?  If this file is normally long then maybe a smaller test file.  Either in a snippet or as an attached file is probably best.
bol
0
 

Author Comment

by:NishantGiri
ID: 24165822
Hi b01scott,

Here I am enclosing the output .doc file and  source .rtf file. You can see that the resulting .doc file having un-bold character.

I changed the extension of .rtf to .doc cause this extension is not allowed. But this is our .rtf(FullProduction-RTF.doc) file.

Looking forward for your reply.

Thank You.

Regards,
Nishant Giri.
Full-Production-Report.doc
FullProduction-RTF.doc
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24173827
Wait ... so the resulting file is a DOC, not an RTF file??  I misunderstood that if it is the case.  The "\b" I suggested is for RTF files.  You can't use ASP (as it comes on the IIS server) to make a real Word document file.  An RTF file would be fine and Word supports those but you seem to already have what you need to bold in one of those files.
bol
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:NishantGiri
ID: 24191513
Hi b0lsc0tt,

So what you suggest to achieve that( make word document from the existing .rtf file and make the rows in bold character generated at run time, you can see through code).

Looking forward for your reply.

Thank You.

Regards,
Nishant.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24196072
Without 3rd party objects or components ASP can't make a Word DOC file.  I know of one component called OfficeWriter (http://officewriter.softartisans.com/) that can be installed to your server and then used by ASP to make and write Word files.  I am not sure how it would work using an RTF file as a "template" for your file but I am almost positive it should do it.  A key though is would you need the more expensive edition of that program to get that ability?  SoftArtisans should be able to help with those details though.
There might be other programs that could be installed and used but I haven't seen or heard of them.  Without some 3rd party help ASP can't do it.  Let me know how this helps or if you have a question.
bol
0
 

Author Comment

by:NishantGiri
ID: 24213799
Hi b0lsc0tt,

We are successfully creating the word document using activeX components. Problem is making few entries in bold using .rtf files as templates. Is there any ways through code that make it possible to make entries in bold character?

Regards,
Nishant.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24216676
What ActiveX component specifically?  The way to bold would depend on it.  None of the default components that are part of IIS would do it so I will need specifics on which you use to find out how to bold or control other formatting.
bol
0
 

Author Closing Comment

by:NishantGiri
ID: 31569153
I apologize for delay in response. Thank you for your prompt reply and suggezstions.

thank you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about a problem I had getting the GPS LocationListener working.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now