Avatar of Venkatkp007
Venkatkp007
 asked on

I need a (small) VBScript to find Junk characters in the Excel sheet

We have a spreadsheet upload process through the website and it is stored in one of the folders in the server. We have a separate VBscript in the server which is processing the spreadsheet. few days back we observed that the spreadsheet contained following junk/funny characters

ntent-Transfer-Encoding: 16bit      

hg±í’ß>  
and the entire spreadsheet looked corrupt with above characters. The spreadsheet got corrupted due to some Portal web server settings which we don't have access too.

Do we have a way in VBScript to check if the spreadsheet is corrupt like this? Can anyone guide me?

Pls let me know if you require more information.
Venkatkp
ASPMicrosoft Excel

Avatar of undefined
Last Comment
ExcelGuide

8/22/2022 - Mon
sybe

There is a bug in Internet Explorer which can cause corruption of uploaded files (or any multipart/form-data). It is relatively easily prevented by avoiding certain character sets in the HTML of the upload form. For example with UTF-8 Internet Explorer does not have that bug.

ExcelGuide

if you still looking for the VBS then you could try the following (although it will need some modification to meet your need, this is just an example that it is possible)
Dim xlObj, xlWbk
Set xlObj = CreateObject("Excel.application")
Set xlWbk = xlObj.Workbooks.Open("C:\test.xls")
 
For i = 1 to 10 'only checking 10 cells in the first column
'where you see the i you can enter your special characters
If xlObj.ActiveWorkbook.Sheets(1).Range("A" & i & "").Value = "i" Then
Msgbox "I found one!"
End If
Next
 
xlObj.ActiveWindow.Close
xlObj.Quit

Open in new window

Venkatkp007

ASKER
Psychotec :

I am not a VB Programmer, but i want to check whether if i need to change the logic in the above program to check the junk characters.?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
sybe

> The spreadsheet got corrupted due to some Portal web server settings which we don't have access too.

Do you know which settings? I can not imagine one.

What will you do with corrupted uploaded spreadsheets? Ignore them? That seems the wisest. If they are corrupted your script will produce an error. Catch that error, and ignore the file. Maybe notice the uploader. But if the same file is uploaded again it might get corrupted in the same way.

Why would you want to know how exactly the spreadsheet is corrupted? It seems logical to check if the script can handle the spreadsheet Yes/No. What happens when someone uploads a non-spreadsheet file?
Venkatkp007

ASKER
sybe

I am just looking for a VB script which will say whether the uploaded spreadsheet is corrupted or not. Nothing else...

Looking for what is happening inside the corrupted sheet is not the solution i am going to do.
sybe

> I am just looking for a VB script which will say whether the uploaded spreadsheet is corrupted or not.

I am just saying that it is pointless to check if a spreadsheet is corrupted in this very special way that you have defined as 'corrupt'. What if a spreadsheet is corrupted in another way, with different junk characters? Will you come back here and ask how to detect that (newly defined)  corruptedness?

The solution I suggest is simply to catch all errors in handling the uploaded spreadsheet, no matter where they come from. By definition the spreadsheet is 'corrupt' if your script can not handle it (that is: if your script is working correctly).
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
ExcelGuide

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.