I am downloading excel files from SharePoint using Python. All works fine except when excel file has special character. below two URLs for reference. I am using URL encoding (import urllib) and works fine for all URLs excepts file has special character. Any idea on what to do?
working fine
_api/web/GetFileByServerRelativeUrl('/sites/11/Documents/C%20F%20D/R%20C%20F%2020200501%20-%20Tecks%20comment.xlsm')/$value
Not working
_api/web/GetFileByServerRelativeUrl('/sites/11/Documents/C%20F%20D/K%20%27%20%27%20-%20%27test.xlsm?')/$value')
file name is -K ' ' - 'test.xlsm
You need to encode all special characters,then use this rest:
/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/dev/Doc/%2520sdff%5E%253d654fd.xlsx')
My file name is:%20sdff^%3d654fd.xlsx
Related
I have an XML file that I'm trying to read with PowerShell. However when I read it, the output of some of the XML objects have the following characters in them: ​
I simply downloaded an XML file I needed from a third-party, which opens in Excel. Then I grab the columns I need and paste them into a new Excel Workbook. Then I map the fields with an XML Schema and then export it as an XML file, which I then use for scripting.
In the Excel spreadsheet my data looks clean, but then when I export it and run the PS script, these strange characters appear in the output. The characters even appear in the actual XML file after exporting. What am I doing wrong?
I tried using -Encoding UTF8, but I'm relatively new to PowerShell and am not sure how to appropriately apply it to my script. Appreciate any help!
PowerShell
$xmlpath = 'Path\To\The\File.xml'
[xml]$xmldata = (Get-Content $xmlpath)
$xmldata.applications.application.name
Example of Output
​ABC_DEF_GHI​.com​​
​JKL_MNO_PQRS​.com​
TUV_WXY_Z.com
AB_CD_EF_GH​.com
This is a prime example of why you shouldn't use the idiom [xml]$xmldata = (Get-Content $xmlpath) - as convenient as it is.[1] The problem is indeed one of character encoding: your file is UTF-8-encoded, but Windows PowerShell's Get-Content cmdlet interprets it as ANSI-encoded in the absence of a BOM - this answer explains the encoding part in detail.Thanks, choroba.
Instead, to ensure that the XML file's character encoding is interpreted correctly, use the following:
# Note: If you know that $xmlPath contains a *full*, native path,
# you don't need the Convert-Path call.
($xmlData = [xml]::new()).Load((Convert-Path -LiteralPath $xmlPath))
This delegates interpretation of the character encoding to the System.Xml.XmlDocument.Load .NET API method, which not only assumes the proper default for XML (UTF-8), but also respects any explicit encoding specification as part of the XML declaration, if present (e.g., <?xml version="1.0" encoding="iso-8859-1"?>)
See also:
the bottom section of this answer for background information.
GitHub proposal #14505, which proposes introducing a New-Xml cmdlet that robustly parses XML files.
[1] If you happen to know the encoding of the input file ahead of time, you can get away with using Get-Content's -Encoding parameter in your original approach ([xml]$xmldata = (Get-Content -Encoding utf8 $xmlpath), but the .Load()-based approach is much more robust.
I have found that downloading a non-unicode Sharepoint Excel file from VBA using URLDownloadToFile works well. However, if the URL has unicode characters (Chinese) then I see that URLDownloadToFileW is required. However, I have not been able to get it to work. The URL is in the Excel Workbook.FullName.
ex.
ret = URLDownloadToFileW(0, ActiveWorkbook.FullName, sAttachFilename, 0, 0)
In this case, ret is non-0. I have tried:
ret = URLDownloadToFileW(0, StrConv(ActiveWorkbook.FullName,vbUnicode), sAttachFilename, 0, 0)
Same result.
Has anyone been able to download unicode URLs in VBA?
For my situation, the Excel workbook is already downloaded and open. Therefore, there is no need to download it again to a file (ex. directly from Sharepoint). For my requirements, simply executing an ActiveWorkbook.SaveCopyAs method works for me.
I mirrored a site to local server with wget and the file names locally look like this:
comments
comments?id=123
Locally these are static files that show unique content.
But when I access second file in browser it keeps showing content from file comments and appends the query string to it ?id=123 so it is not showing content from file comments?id=123
It loads the correct file if I manually encode the ? TO %3F in browser window and I type:
comments%3Fid=123
Is there a way to fix this ? Maybe make apache stop treating ? as query separator and treat it as file name character ? Or make an URL rewrite and change ? into %3F ?
Edit: Indeed too many problems caused by ? in file name and requests. I ended up using the wget option --restrict-file-names=windows that would convert ? into an # when saving file name.
The short answer is "don't do that."
The longer answer is that ? is a reserved character in URLs, using it as a part of a filename is going to cause problems forever, and the recommended solution is to pick a different character to use in those filenames. There are many to choose from - just avoid ? & # and # and you'll probably be fine.
If you insist on keeping the file name (or if you don't have an option) try:
RewriteCond %{QUERY_STRING} (.*)
RewriteRule (.*) $1%%3F%1 [NE]
However, this is going to fire any time you have a query string, which is likely not what you want.
I have an Excel file that will be saved as an .csv file for importation into an email automation system. In a function I need to return a piece of HTML code as text.
=IF(A2<0,"CHECKMARK CODE",A2)
The "CHECKMARK CODE" needs to be replaced by:
> < span style="font-size:16px">& #10003;</span>.
For this post, spaces were added to prevent code from display as a checkmark.
However, all my attempts at the format_text function or adding apostrophes only yields errors.
How do I return this as text exactly as needed by the email automation system?
Please try escaping the double quotes:
=IF(A2<0,"<span style=""font-size:16px"">& #10003;</span>",A2)
I am generating a csv file.
I would like to set up the delimiter dynamically, that is, get the value of the list-separator set up on the pc and then use it in my csv.
Is it possible??
No it's not. You want your csv to open in Excel. Correct? Then use [TAB] and direct the file to be saved ".xls" and not ".csv". The worst case is a warning message at opening regarding the file format for the user, but data will be visible in cells for sure.
Another approach for excel files is to use Excel(X)ML; it's very simple for raw data (http://office.microsoft.com/en-us/excel-help/overview-of-xml-in-excel-HA010206396.aspx)
I did generate a CSV using ',' as delimiter..But on my client side, it was not working. I replaced the delimiter by ';' and it works on the client side.
That means the client expected ; instead of ,. You cannot know what the client expects unless he tells you. There are an uncountable number of programs that use the CSV format, there's no universal way to figure out which delimiter they expect. Usually it works the other way around: you create the CSV and specify to the client what delimiter you have used. There's no technical protocol to do this though, CSV is too informal to have any such universal specification.