How to upload and then open ms-word or ms-excel files

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Interested
Rating: 10
Joined: Nov 10, 2011
Company: 1A Software e.U

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

 
#2
People who like this:0Yes/0No
Just came
Rating: 0
Joined: Jan 10, 2019
Company: 1c developer

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

 
#3
People who like this:0Yes/0No
Interested
Rating: 10
Joined: Nov 10, 2011
Company: 1A Software e.U

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

 
#4
People who like this:0Yes/0No
Active user
Rating: 4
Joined: Mar 10, 2017
Company: Rufinor

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

 
Subscribe