Desktop version

Main > Forum > 1C:Enterprise Platform > 1C:Enterprise – Business applications platform > How to upload and then open ms-word or ms-excel files

Forum

Search UsersRules
How to upload and then open ms-word or ms-excel files
#1
Interested
Points:: 0
Joined:: Nov 10, 2011

Hello!

I can upload PDF-Files into 1C-Application and then open them but do not know how does it work with MS-Word or MS-Excel files.
Thank you in advance for every advice!

Regards,
Lioudmila

Profile
#2
Just came
Points:: 0
Joined:: Jan 10, 2019

Hello, Lioudmila,

There are several ways to import data from Word and Excel files into 1C. The most common is - using of COM Objects. In the case of Excel tables, I often use this way (using SpreadSheetDocument instead of COM-object):

FileOpenDialog = new FileDialog(FileDialogMode.Open);
FileOpenDialog.Filter = "Excel sheet 97 (*.xls)|*.xls|Excel workbook (*.xlsx)|*xlsx";
FileOpenDialog.Multiselect = False;
FileOpenDialog.Title = "Choose Excel file to open";

If FileOpenDialog.Choose() Then
               // --- Parsing choosed file
ExcelFileName = FileOpenDialog.FullFileName;
TableDoc = new SpreadsheetDocument;
TableDoc.Read(ExcelFileName);
LinesCount = TableDoc.PageHeight;

LineNumber = 1;
ColNumber = 1;

While LineNumber <= LinesCount Do
Value = TableDoc.Area(LineNumber, ColNumber).Text; //you can use .Value property also
Message(Value);
LineNumber = LineNumber + 1;
EndDo

EndIf;


it works ;)

it also works in the opposite direction - you can save a SpreadSheetDocument to an XLS file using

TableDoc.Write ("FileName", SpreadsheetDocumentFileType.XLSX);

use the Syntax Help on "SpreadsheetDocumentFileType: type to view all file formats

Profile
#3
Interested
Points:: 0
Joined:: Nov 10, 2011

Thank you for your answer!

It is not what I really mean. I have this code for PDF:

Code
&AtClient
Procedure LoadFile1(Command)
  StorageName1 = "";
   FileName = Object.FileName;
   If PutFile(StorageName1, FileName, FileName, True, UUID) Then
//      Object.FileDescr = FileName;
      LoadFileServer1(StorageName1);
   EndIf;

EndProcedure

&AtServer
Procedure LoadFileServer1(StorageName1)
   Message(StorageName1);
   ObjectValue = FormDataToValue(Object, Type("DocumentObject.PurchaseInvoice"));
   ObjectValue.Storage1 = New ValueStorage(GetFromTempStorage(StorageName1));
   ObjectValue.Write();
   ValueToFormData(ObjectValue, Object);

EndProcedure


&AtClient
Procedure OpenFile1(Command)
   TempFileName = GetTempFileName("pdf");
   StorageURL = GetURL(Object.Ref, "Storage1");
   Message(StorageURL);
   If StorageURL <> "" Then
   GetFile(StorageURL, TempFileName, False);   
   RunApp(TempFileName);
   Else
   Message("Keine Datei");
   EndIf;

EndProcedure


How can I do it with excel or word?
Thank you!

Regards,
Lioudmila

Profile
#4
Active user
Points:: 0
Joined:: Mar 10, 2017

Hello Lioudmila!

I think your code will work for xls and doc files too.

Just replace pdf by xls and doc respectively.

Kind regards,
Alex

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.