Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 795
  • Last Modified:

Creating word report using RTF document Loose formating in vbscript

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
NishantGiri
Asked:
NishantGiri
  • 5
  • 5
1 Solution
 
b0lsc0ttCommented:
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
 
NishantGiriAuthor Commented:
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
 
b0lsc0ttCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
NishantGiriAuthor Commented:
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
 
b0lsc0ttCommented:
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
 
NishantGiriAuthor Commented:
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
 
b0lsc0ttCommented:
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
 
NishantGiriAuthor Commented:
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
 
b0lsc0ttCommented:
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
 
NishantGiriAuthor Commented:
I apologize for delay in response. Thank you for your prompt reply and suggezstions.

thank you.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now