Ask a Question

Reading text from excel file while keeping formatting using JScript

_angelo
Occasional Contributor

Reading text from excel file while keeping formatting using JScript

Hello,



I'm trying programmatically trying to read some data from an Excel file. My code is in JScript and based on the example in the TestComplete help file (see below). The problem I have is that the formatting from the Excel file (bold, underline, and italics) is removed when I read the cells of the Excel file into a String. Is there any way to keep that formatting?



Thank you in advance.



Angelo



PS - Below is the code from TestComplete help that mine is based on.



var RecNo;

 

// Posts data to the log (helper routine)

function ProcessData()

{

  var Fldr, i;

 

  Fldr = Log.CreateFolder("Record: " + aqConvert.VarToStr(RecNo));

  Log.PushLogFolder(Fldr);

 

  for(i = 0; i < DDT.CurrentDriver.ColumnCount; i++)

    Log.Message(DDT.CurrentDriver.ColumnName(i) + ": " + aqConvert.VarToStr(DDT.CurrentDriver.Value(i)));

 

  Log.PopLogFolder();

  RecNo = RecNo + 1;

}

 

// Creates the driver (main routine)

function TestDriver()

{

  var Driver;

 

  // Creates the driver

  // If you connect to an Excel 2007 sheet, use the following method call:

  // Driver = DDT.ExcelDriver("C:\\MyFile.xls", "Sheet1", true);

  Driver = DDT.ExcelDriver("C:\\MyFile.xls", "Sheet1");

 

  // Iterates through records

  RecNo = 0;

  while (! Driver.EOF() )

  {

    ProcessData(); // Processes data

    Driver.Next(); // Goes to the next record

  }

 

  // Closing the driver

  DDT.CloseDriver(Driver.Name);

}
2 REPLIES 2

RE: Reading text from excel file while keeping formatting using JScript


Hi Angelo,





To do this, you need to work with Excel via COM. A sample project demonstrating how to work with Excel is shipped with TestComplete. You can find it here:

Windows 7, Windows Vista and Windows Server 2008:

<Users>\Public\Documents\TestComplete 7 Samples\Scripts\MSOffice\

Other operating systems:

<Documents and Settings>\All Users\Documents\TestComplete 7 Samples\Scripts\MSOffice\





Please see this MSDN Library article containing information about the Excel object model.
--
Dmitry Nikolaev

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
_angelo
Occasional Contributor

RE: Reading text from excel file while keeping formatting using JScript

That worked perfectly. Thanks!
cancel
Showing results for 
Search instead for 
Did you mean: