Solved

Creating word report using RTF document Loose formating in vbscript

Posted on 2009-04-11
12
760 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is an explanation of a simple data model to help parse a JSON feed
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

790 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