We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Change cell backgroundcolor (using Classic ASP)

I'm trying to change the background color of a cell at a specific bookmark using:

builder.movetobookmark(strBM)

builder.Cellformat.Shading.BackgroundPatternColor=System.Drawing.ColorTranslator.FromHtml("#c0c0c0")

It moves to the bookmark properly, but I get this error on the next line:

Microsoft VBScript runtime error '800a01a8'

Object required: ''

It's like it doesn't understand "System.Drawing" or have access to it. Any ideas?

Hi Bill,


Thanks for your inquiry. Please create a wrapper class in C#/VB.NET if you want to use Aspose.Words for .NET via COM Interop in classic ASP. Please refer to the following article for details:
http://www.aspose.com/docs/display/wordsnet/Use+Aspose.Words+for+.NET+via+COM+Interop

Please let us know if we can be of any further assistance.

Best regards,
Awais

That did not help...

I'm actually just trying to change the background color of the row where the bookmark is located. I'm easily able to move to the bookmark and read the height using:
builder.movetobookmark(strBM)
response.write builder.RowFormat.height

How do I change the background color of the row which contains the bookmark? The row only contains one cell.





Hi Bill,


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Aspose.Words generated output document which shows the undesired behavior.
  • Your expected Word document which shows the correct result. Please create this document using Microsoft Word for our reference.
  • Please attach complete source code that helps us reproduce your problem on our end.

As soon as you get these pieces of information ready, we’ll start investigation into your issues and provide you more information.

Best regards,

Here is the code and a simple document as a sample. This will duplicate the errror.


<%
on error Goto 0
myOpenFile=“d:\gfs\000000000\templates\sf330\sample.doc”
mySavedFile=“d:\gfs\000000000\templates\sf330\saved.doc”

Set objWord = CreateObject(“Aspose.Words.ComHelper”)
Set objDoc = objWord.Open(myOpenFile)
Set builder = CreateObject(“Aspose.Words.DocumentBuilder”)
builder.Document = objDoc

builder.movetobookmark(“ShadedArea”)
response.write builder.RowFormat.height

'builder.Cellformat.Shading.BackgroundPatternColor = RGB(r,g,b)
'builder.Cellformat.Shading.BackgroundPatternColor = Color.Red
'builder.Cellformat.Shading.BackgroundPatternColor =ColorTranslator.ToOle(vbRed)

objDoc.Save mySavedFile

set objDoc = nothing
set objWord = nothing
set builder = nothing

%>





Hi Bill,


Thanks for the additional information. We are checking this scenario and will get back to you soon.

Best regards,

Hi Bill,


Thanks for being patient. It seems that you can’t change BackgroundPatternColor in classic ASP. That’s why you should create wrapper class. For more information please see the following link.
How to create a wrapper to assist in calling Aspose.Words methods from classic ASP.

Best regards,
Problem:
I don't have Visual Studio.

There's no other way?

Can somone build me a quick DLL that exposes the BackgroundPatternColor method?

Here's what I need to do:
builder.Cellformat.Shading.BackgroundPatternColor = RGB(r,g,b)

Hi Bill,


Thanks for your request. We are working over your query and will get back to you soon.

Best regards,
I've now got Visual C++ 2008 running on a Windows 2003 Server.

// AsposeComWrapper.h

using namespace System;
using namespace Aspose::Words;

namespace AsposeComWrapper {

// What's goes here?
}

Can anyone help on this?

I need to do this:
builder.Cellformat.Shading.BackgroundPatternColor = RGB(r,g,b)

or this:
builder.Cellformat.Shading.BackgroundPatternColor=System.Drawing.ColorTranslator.FromHtml("#c0c0c0")

Hi Bill,


Thanks for your inquiry. Please try using the following code snippet:

using Aspose.Words;

using Aspose.Words.Saving;

using Aspose.Words.Tables;

namespace AsposeComWrapper

{

public class Methods

{

public Methods() { }

public void SetShadingColor(object d, object outPath)

{

Document doc = (Document)d;

DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToBookmark("ShadedArea");

builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.Red;

doc.Save(outPath.ToString());

}

...


<%<o:p></o:p>

Dim lic

Set lic = CreateObject("Aspose.Words.License")

lic.SetLicense("C:\Temp\Aspose.Total.lic")

Dim helper

Set helper = CreateObject("Aspose.Words.ComHelper")

Dim doc

set doc = helper.open("C:\Temp\Sample.doc")

Dim comHelper

Set comHelper = CreateObject("AsposeComWrapper.Methods")

comHelper.SetShadingColor doc, "C:\Temp\out.pdf"

%>


I hope, this helps.

Best regards,

I did get that working, thanks.


Is there anyway to do that so that passing the instance of the “builder” from my ASP Class script to the DLL method?

So instead of passing the file name as a parameter:
SetShadingColor(“c:\old.doc”, “c:\new.doc”)

I can simply pass the instance already being used in my script:
SetShadingColor(object builder)

Hi Bill,


Thanks for your inquiry. Please go through the following example:

using System.Drawing;

using Aspose.Words;<o:p style=“position: relative;”></o:p>

<o:p style=“position: relative;”> </o:p>

namespace AsposeComWrapper<o:p style=“position: relative;”></o:p>

{<o:p style=“position: relative;”></o:p>

public class Methods<o:p style=“position: relative;”></o:p>

{<o:p style=“position: relative;”></o:p>

public void SetFontColor(object builder, object colorCode)<o:p style=“position: relative;”></o:p>

{<o:p style=“position: relative;”></o:p>

DocumentBuilder b = (DocumentBuilder) builder;<o:p style=“position: relative;”></o:p>

b.Font.Color = Color.FromName(colorCode.ToString());<o:p style=“position: relative;”></o:p>

}<o:p style=“position: relative;”></o:p>

}<o:p style=“position: relative;”></o:p>

}


Dim lic<o:p style=“position: relative;”></o:p>

Set lic = CreateObject(“Aspose.Words.License”)<o:p style=“position: relative;”></o:p>

lic.SetLicense(“C:\Temp\Aspose.Words.lic”)<o:p style=“position: relative;”></o:p>

<o:p style=“position: relative;”> </o:p>

’ Open document<o:p style=“position: relative;”></o:p>

Dim doc<o:p style=“position: relative;”></o:p>

Set doc = CreateObject(“Aspose.Words.Document”)<o:p style=“position: relative;”></o:p>

<o:p style=“position: relative;”> </o:p>

’ Create DocumentBuilder.<o:p style=“position: relative;”></o:p>

Dim builder<o:p style=“position: relative;”></o:p>

Set builder = CreateObject(“Aspose.Words.DocumentBuilder”)<o:p style=“position: relative;”></o:p>

builder.Document = doc<o:p style=“position: relative;”></o:p>

<o:p style=“position: relative;”> </o:p>

dim helper<o:p style=“position: relative;”></o:p>

Set helper = CreateObject(“AsposeComWrapper.Methods”)<o:p style=“position: relative;”></o:p>

helper.SetFontColor builder, “Red”<o:p style=“position: relative;”></o:p>

<o:p style=“position: relative;”> </o:p>

builder.Write(“Hello world!!!”)<o:p style=“position: relative;”></o:p>

<o:p style=“position: relative;”> </o:p>

’ Save output document<o:p style=“position: relative;”></o:p>

doc.Save(“C:\Temp\out.doc”)


I hope, this helps.

Best regards,

Hi Bill,


Thanks for your inquiry. Please go through the following example:

using System.Drawing;

using Aspose.Words;<o:p style=“position: relative;”></o:p>

<o:p style=“position: relative;”> </o:p>

namespace AsposeComWrapper<o:p style=“position: relative;”></o:p>

{<o:p style=“position: relative;”></o:p>

public class Methods<o:p style=“position: relative;”></o:p>

{<o:p style=“position: relative;”></o:p>

public void SetFontColor(object builder, object colorCode)<o:p style=“position: relative;”></o:p>

{<o:p style=“position: relative;”></o:p>

DocumentBuilder b = (DocumentBuilder) builder;<o:p style=“position: relative;”></o:p>

b.Font.Color = Color.FromName(colorCode.ToString());<o:p style=“position: relative;”></o:p>

}<o:p style=“position: relative;”></o:p>

}<o:p style=“position: relative;”></o:p>

}


Dim lic<o:p style=“position: relative;”></o:p>

Set lic = CreateObject(“Aspose.Words.License”)<o:p style=“position: relative;”></o:p>

lic.SetLicense(“C:\Temp\Aspose.Words.lic”)<o:p style=“position: relative;”></o:p>

<o:p style=“position: relative;”> </o:p>

’ Open document<o:p style=“position: relative;”></o:p>

Dim doc<o:p style=“position: relative;”></o:p>

Set doc = CreateObject(“Aspose.Words.Document”)<o:p style=“position: relative;”></o:p>

<o:p style=“position: relative;”> </o:p>

’ Create DocumentBuilder.<o:p style=“position: relative;”></o:p>

Dim builder<o:p style=“position: relative;”></o:p>

Set builder = CreateObject(“Aspose.Words.DocumentBuilder”)<o:p style=“position: relative;”></o:p>

builder.Document = doc<o:p style=“position: relative;”></o:p>

<o:p style=“position: relative;”> </o:p>

dim helper<o:p style=“position: relative;”></o:p>

Set helper = CreateObject(“AsposeComWrapper.Methods”)<o:p style=“position: relative;”></o:p>

helper.SetFontColor builder, “Red”<o:p style=“position: relative;”></o:p>

<o:p style=“position: relative;”> </o:p>

builder.Write(“Hello world!!!”)<o:p style=“position: relative;”></o:p>

<o:p style=“position: relative;”> </o:p>

’ Save output document<o:p style=“position: relative;”></o:p>

doc.Save(“C:\Temp\out.doc”)


I hope, this helps.

Best regards,