Jump to content
Sign in to follow this  
Attckdog

Excel Format Cell as Text

Recommended Posts

Attckdog

I've got a tab delimited text file that needs column headers added.

As you might be able to see it's for an Amazon Order confirmation File.

With my current experience with autoit I figured the best way to make this happen would be to use excel.

Only problem is that excel is being a punk and changing my numbers to short hand.

The numbers that are being changed are FedEx Tracking numbers like: 064089467117955

End up like this: 6.40895E+13

So i was looking for a better way to do this or a way to prevent my cells from being changed.

Here's my Code:

FileCopy("Y:\New Folder\HOLDFILEEXPORT.txt", "C:\Amazon\HOLDFILEEXPORT.txt", 1)
FileCopy("C:\Amazon\HOLDFILEEXPORT.txt", "C:\Amazon\HOLDFILEEXPORT.xls", 1)

$oExcel = _ExcelBookAttach("C:\Amazon\HOLDFILEEXPORT.xls")
_ExcelRowInsert($oExcel, 1, 1)
Sleep(10)
_ExcelWriteCell($oExcel, "order-id", 1, 1)
Sleep(10)
_ExcelWriteCell($oExcel, "order-item-id", 1, 2)
Sleep(10)
_ExcelWriteCell($oExcel, "quantity", 1, 3)
Sleep(10)
_ExcelWriteCell($oExcel, "ship-date", 1, 4)
Sleep(10)
_ExcelWriteCell($oExcel, "carrier-code", 1, 5)
Sleep(10)
_ExcelWriteCell($oExcel, "carrier-name", 1, 6)
Sleep(10)
_ExcelWriteCell($oExcel, "tracking-number", 1, 7)
Sleep(10)
_ExcelWriteCell($oExcel, "ship-method", 1, 8)
Sleep(10)
_ExcelBookClose($oExcel)

A true renaissance man

Share this post


Link to post
Share on other sites
water

There is an extended Excel UDF available called with many useful functions extending the functionality of the UDF that comes with AutoIt.

Function _ExcelNumberFormat should do what you want.

Example: _ExcelNumberFormat($l_ExcelReport,"@","A1:A65536") formats the specified range as text.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
kylomas

Attckdog,

Find a better behaved copy of Excel...if it was working before the headers then the cell format changed.

kylomas

Edit: whoops, too slow, water beat me in...good luck!!

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Zedna

There is an extended Excel UDF available called with many useful functions extending the functionality of the UDF that comes with AutoIt.

Function _ExcelNumberFormat should do what you want.

Example: _ExcelNumberFormat($l_ExcelReport,"@","A1:A65536") formats the specified range as text.

Thanks for info. I can use it in the future too.

Do you know how to reformat whole column? How to specify range for whole column?

_ExcelNumberFormat($l_ExcelReport,"@","A1:A65536") ; formats the specified range as text.

Share this post


Link to post
Share on other sites
water

I'm not at my windows PC at the moment but IIRC you specify a column (e.g. column A ) as "A:A"

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
jchd

@Attckdog

I don't get why you insist of going thru Excel (causing issues) just for the purpose of inserting a header line in a .CSV

First, AFAICT Amazon delivers CSV files with headers. At least it was the case until recently where we stopped selling there.

Now, if ever the CSV files you get miss the header line and all you want in the first place is have it, why not just prepending it to the CSV? That's 5 lines of code.

Finally, I guess you're going to process your CSV file somehow, presumably with AutoIt. If that's the case you don't even need the first step.

In any case, be warned that all platforms (Amazon, Paypal, eBay, YouNameIt) have great fun changing their CSV columns, headers and even semantics from time to time without any prior nor post notice. That means that you'll have to sanitize this kind of input with extreme caution at the risk of processing wrongly interpreted data, up to random garbage.

OMG I was talking about CSVs, but Amazon delivers TSV (tab separated values). That makes no difference anyway.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Attckdog

@Attckdog

I don't get why you insist of going thru Excel (causing issues) just for the purpose of inserting a header line in a .CSV

OMG I was talking about CSVs, but Amazon delivers TSV (tab separated values). That makes no difference anyway.

Yeah I just use the excel method because most of my experience with Autoit is in processing information from excel files.

So my first thing to attempt was to use what I already knew how to do.

What all would i use to edit the file in autoit without using excel stuff? I haven't done anything like that without excel files.

I'm not worried about the headers changing in Amazon because in the event of something not working properly it will just fail.

I'm only using these files to confirm with the tracking numbers. I will have to baby sit the script any how so no worries.


A true renaissance man

Share this post


Link to post
Share on other sites
Attckdog

Thanks water for the help. I eventually got the excel method to work.

After looking at the finished product I decided to scrap it. jchd was quite right. I was taking the hardest route.

After reading up on processing text files I found it was actually quite easy.

Here is the code I whipped up to use in place of what I was using.

Anyone is welcome to use it.

#include<File.au3>
Local $ReadFileArray
_FileReadToArray(@ScriptDir & "\Test.txt", $ReadFileArray)
FileWrite(@ScriptDir & "\TestResult!.txt", "order-id order-item-id quantity ship-date carrier-code carrier-name tracking-number ship-method" & @CRLF)
$file = FileOpen(@ScriptDir & "\TestResult!.txt", 1)
_FileWriteFromArray($file, $ReadFileArray, 1)
FileClose($file)

This will Make the confirmation file i needed with the desired column heads.

/Thead


A true renaissance man

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • reida
      By reida
      Hello. On page there is mail address. How to keep in a text file this address? 
      It is page and email
      https://alpari.com/
      info@alpari.com
    • nooneclose
      By nooneclose
      My program has to first search for names in Column D that do not match up with column C. I got that search to work using arrays. It was slow and I could not figure out how to delete them so I just manually put coded the names that do not belong. I found their cell location but I do not know how to store that location and delete it.
      This is what I have so far.
      Local $NameToDelete1[6]  = _Excel_RangeFind($OpenWorkbook, "Smith, Bill") _ArrayDisplay($NameToDelete1, "Excel UDF: _Excel_RangeFind Example 1", "", 0, "|", "Sheet|Name|Cell|Value|Formula|Comment") _Excel_RangeDelete($OpenWorkbook.ActiveSheet, $NameToDelete1[2], $xlShiftUp)  
      Please help, I wanted to have this program done yesterday but I did not see this problem until yesterday. 
    • nooneclose
      By nooneclose
      I need to perform a subtotal in excel and I would like to automate this process using Autoit if possible like always any and all help will be greatly appreciated. 
      I can not find a good example but the two from Microsoft. Here is one of the two from msdn.microsoft.com/en-us/vba/excel-vba/articles/range-subtotal-method-excel
      I do not really understand how to translate this into AutoIt, but I gave it a try and here is what I have.
      $OpenRange      = "A1:E200" $xlSum          = -4157 $Added_Array[2] = [2, 3] $OpenRange.Subtotal("B1", $xlSum, $Added_Array, True, False, True) I just need to perform a subtotal on a range based on a header called department, and then perform a sum on the results.
    • nooneclose
      By nooneclose
      How to use _Excel_RangeSort to sort my excel file by three different headers Column A1, B1, and C1 have headers on which I want to sort by. The headers on which I want to sort are department, employee type, and name.
      I still really new to AutoIt so I do not actually know how to properly start this line or lines of code, to be honest. The example code is the best I can do.
      _Excel_RangeSort($OpenWorkbook, Default, "A1:C1", "1:1", $xlDescending, Default, $xlYes, Default, $xlSortRows) I just need to sort by those three headers in that order of department, employee type, and name, plus in descending order.
       
      any and all help would be greatly appreciated.  Thank you!
    • caramen
      By caramen
      Hey.  
       
      I requested help about how to get a value from a text in a variable. 
      Now i know how to do that. But i learned with the command FileRead. Now i whould like to know how to replace the command :
      FileRead('Dossier.txt') The purpose is to read a webpage text. To find some value inside. 
       
      Btw i tryed to play with WindowsInfo.au3 but i dont got much thing.  
×