SaveAs function when saving to excel from Python - xlsx

I know openlyxl , xlrd , xlwt, etx have a save method. But I was wondering if they have a save as method. So I want it to open an existing workbook, edit it, but then do a save as therefore leaving the original excel file intact and saving the original with modifications I made in a different location.

With openpyxl you must always specify the name of the file that you are saving the workbook as.

Related

Logic Apps SharePoint Connector - Move file with new file name

We have a integration requirement to move files from one folder to another in SharePoint Online. The new file name in the destination folder needs to be suffixed with the current datetime. For instance, if the source filename is Myfile.csv, it should be moved with the new name Myfile_2021-04-15T15:39:23.csv to the destination folder.
Using the Logic App SharePoint Move file action, I haven't been able to achieve this
If another file is already there is an enum and I'm unable to provide a custom expression for it. Further, with this option files are only renamed if there's a file with the same name already existing in the destination folder. Whereas our requirement is to attach datetime to all files that are being transferred, independent whether the file already exist in the destination folder or not.
How can I best achieve this?
Thanks in advance for any assistance.
Since the "Move file" action doesn't provide a feature for us to specify the new file name, I think the requirement can't be implemented by this action. You can just use other action to do it.
For example, use "Get file content" action to get the file content.
Then use "Create file" action to create the new file in the location which you want.
You can specify a name which you want in the "File name" input box.
By the way, the "Get file content" action doesn't provide an expression of file name for us to use in second step. But I noticed that you have got Full path in your description, so you can substring the Full path to get the original file name. And then use utcNow() method to get the current date and append it to file name.

File upload and attach in Acumatica

I'm actually new in Acumatica Framework. I'm having some issues to understand how to attach the file. The problem is that in this answer Attach file to data row they talk about
PXNoteAttribute.SetFileNotes(Base.Caches[typeof(DAC)], dacRecord, file.UID.Value);
I do not understand what do they refer about "Base.Caches[typeof(DAC)], dacRecord", I've already saved the file but the step of setting the file is my problem...
You need to provide the Cache object corresponding to the type of your Record and the Record itself. For example if you need to attach file to SOOrder you will provide values like below:
var currentSOOrder = soOrderEntry.Document.Current;
PXNoteAttribute.SetFileNotes(soOrderEntry.Caches[typeof(SOOrder)], currentSOOrder , file.UID.Value);

Foreach Loop Container failed to traverse through all files in a folder

I have one temp folder C:\Mydata inside that i have .csv files with name
demo1.csv demo2.csv...etc
Now I want to insert data from all those files into database table
for this I have taken Foreach Loop Container in the property Directory I mention
C:\Mydata
inside Foreach Loop Container taken a Data Flow Task in that Flat File Source is there in the connection manager property in file name what should I mention, so that it will traverse through all folder and all files whose extension is .csv
I did like C:\DEMO\*.csv which is giving me error :
no file found path is wrong
From what i interpreted, your issue was assigning the resulting file from the foreach to the connector.
To do that you need to assign the filename from the Foreach to a variable.
The first step to be taken is to create the variable. To do that you need to activate the "Variables" window:
Then you need to create a new variable of type string and rename it.
For more information on SSIS variables and how to create them, see http://msdn.microsoft.com/en-us/library/ms140216.aspx
Now you need to assign the new variable (in this case i named it "filename") to the foreach loop:
NOTE THAT WHILE THE OPTION "Name Only" IS SELECTED IN THE FIRST WINDOW, IN YOUR CASE YOU PROBABLY WANT "Fully Qualified"!!
The screenshot was taken from a working project i have and i am using only the name (Name Only) as opposed to the full path (Fully Qualified)
After doing that you need to assign that variable to your flat file connector using expressions:
Which version of MSSQL and SSIS are you using? And why are you using C:\Mydata in one place and C:\DEMO in another?
The basic technique of looping over files is described here.
There is lot of information about these steps in the documentation and on the web. If you need more help, please be as specific as possible about what you've tried, what isn't working, what versions you're working with etc.

Cakephp excel report using XLS helper gives an warning message in windows and displays entire xml structure in open office

I'm using cakephp XLS helper to generate Excel report in my project.
But the generated file is giving warning message in windows system as below.
Similarly the same file displays the entire xml mark-up in open-office on linux as below.
Part of the view file code is as below.
$xls->setHeader('Report_'.date('Y_m_d'));
$xls->addXmlHeader();
$xls->setWorkSheetName('Enrollment Report');
//1st row for columns name
$xls->openRow();
$xls->writeString('ID');
$xls->writeString('Zipcode');
My Client wants a proper excel report with-out any warnings in windows.
Please suggest me any excel helper for cakephp which will generate proper excel file on all the platform and different application.
Your problem is that you are using a helper that puts your data in xml format. Excel can read XML and HTML but with a warning. You should use the one that Ivo suggested in the comments. LINK
This helper really makes an xls valid format, that complys with open office and office. Also, this helper relies on PHPExcel class that is constantly updated here so your code will be easy to upgrade if needed.
Remember to follow instructions given in the helper page.
I've tried a lot of this xls helper for cakephp, but neither one work as expected, either outdated or create xml o html tables or didn't work at all, haven't tried this one though... still creating a helper using PHPExcel shouldn't give you much trouble, you may use this tutorial as a how to base to modify the helper.
I think you need to set the mime-type. This has happened to me in the past and it was when the mime-type of an older excel helper was set to an out-dated value.
The code from the linked (by Ivo) helper has the following:
function _output($title) {
header("Content-type: application/vnd.ms-excel");
header('Content-Disposition: attachment;filename="'.$title.'.xls"');
header('Cache-Control: max-age=0');
$objWriter = new PHPExcel_Writer_Excel5($this->xls);
$objWriter->setTempDir(TMP);
$objWriter->save('php://output');
}
I would make sure you are:
a) using the newest helper (http://bakery.cakephp.org/articles/melgior/2010/01/26/simple-excel-spreadsheet-helper)
b) that the mime-type is actually set.
c) that that specific mime-type is accurate.

ssis - flat file source - The process cannot access the file because it is being used by another process

Am attempting to use SSIS flat file source to read a log file being actively written to. Looping and waiting for the file to be released is not practical as this is an active log file held by a service.
Ideally, I'm looking for a setting upon the flat file source, similar to the C# code below. If not that, what route can I take to read the flat file? I'm attempting to stay within SSIS as I sincerely can't believe this can't be done with stock parts and assume I'm just missing something.
Using C#, I can successfully open the exact file upon which the flat file source errors
System.IO.FileStream file
= new System.IO.FileStream
(
file_to_hash.FullName
, System.IO.FileMode.Open
, System.IO.FileAccess.Read
, System.IO.FileShare.ReadWrite
);
This is the error message experienced in SSIS:
Warning: 0x80070020 at Data Flow Task, Flat File Source [1]: The process cannot access the file because it is being used by another process.
Error: 0xC020200E at Data Flow Task, Flat File Source [1]: Cannot open the datafile "XXX".
both ideas by tim and cade would work. I chose Tim's approach - copying the file b/c I already had the code ( both the copy and the data tranformation ), and changing the name/path of the file going into the data transformation was a configuration setting of the app being built. Wish I could mark it answered, but asked the question as an unregistered user.
You probably need to write a custom data source - possibly as simple as a script task.

Resources