Тёмный

Visual studio C# Tutorial : Microsoft Word file 

Madsycode
Подписаться 8 тыс.
Просмотров 63 тыс.
50% 1

Опубликовано:

 

21 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 151   
@TheSinnA.
@TheSinnA. Год назад
I search that subject about during 3 mounth and I already watch and read almost every document on internet at the and ı saw your video Thank you so so much
@RajivdixitjiOfficial
@RajivdixitjiOfficial 6 лет назад
I face this error.. kindly help me to fix it. Error 1 'object' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) C:\Users\Rinku Kaushik\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 45 38 WindowsFormsApplication1
@Madsycode
@Madsycode 6 лет назад
I don't get your point
@abdulhamitkoskulu9331
@abdulhamitkoskulu9331 6 лет назад
thank you man i was searching this for days those are the codes for who doesnt want to write :D private void findandreplace(word.Application wordapp, object tofindtext, object replacewithtext) { object matchcase = true; object matchwholeword = true; object matchwildcards = false; object matchsoundlike = false; object nmatchallforms = false; object forward = true; object format = false; object matchkashida = false; object matchdiactitics = false; object matchalefhamza = false; object matchcontrol = false; object read_only = false; object visible = true; object replace = 2; object wrap = 1; wordapp.Selection.Find.Execute(ref tofindtext, ref matchcase, ref matchwholeword, ref matchwildcards, ref matchsoundlike, ref nmatchallforms, ref forward, ref wrap, ref format, ref replacewithtext, ref replace, ref matchkashida, ref matchdiactitics, ref matchalefhamza, ref matchcontrol); } private void createworddocument(object filename,object saveas) { word.Application wordapp = new word.Application(); object missing = Missing.Value; word.Document myworddoc = null; if (File.Exists((string)filename)) { object readOnly= false; object isvisible = false; wordapp.Visible = false; myworddoc = wordapp.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing , ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing , ref missing, ref missing); myworddoc.Activate(); this.findandreplace(wordapp, "", textBox1.Text); this.findandreplace(wordapp, "", textBox2.Text); } else { MessageBox.Show("dosya bulunamadı"); } myworddoc.SaveAs2(ref saveas, ref missing, ref missing, ref missing , ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing , ref missing, ref missing, ref missing, ref missing, ref missing); myworddoc.Close(); wordapp.Quit(); MessageBox.Show("dosya oluşturuldu"); }
@Madsycode
@Madsycode 6 лет назад
Abdulhamit KOŞKULU glad to no it help someone thx
@Madsycode
@Madsycode 6 лет назад
And please subscribe : )
@RajivdixitjiOfficial
@RajivdixitjiOfficial 6 лет назад
i face this error .. please help me to fix this... Error 1 'object' does not contain a definition for 'Value' and no extension method 'Value' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?) C:\Users\Rinku Kaushik\Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs 45 38 WindowsFormsApplication1
@alexpaskal8345
@alexpaskal8345 2 года назад
This is exactly what I needed. Many thanks from Ukraine!
@Madsycode
@Madsycode 2 года назад
am glad to know it helped! 😂
@what_is_lovechik
@what_is_lovechik 2 года назад
Це ж ж треба такий комент зустріти під цим відео)
@janphillipjuntado
@janphillipjuntado 3 года назад
Thanks for this bro! I love how you introduced the find and replace method to replace text. really saved me a lot of time.
@Madsycode
@Madsycode 3 года назад
glad to know its usefull!
@malcolmmathias5881
@malcolmmathias5881 3 года назад
I know it is kinda randomly asking but does anybody know a good website to stream new movies online?
@ruimiguel2358
@ruimiguel2358 2 года назад
Hi sir, the video is really well explained, but I've got a question, basically I've managed to create a report with the code provided by you, but now I've got another part of the same report in another form page, just to simplify for the user, how do i "link" them both together in one word file report?
@dimitrisoultis2133
@dimitrisoultis2133 2 года назад
HI! Great thanks for this video, it helped me a lot and was my support to generate a word document :) One question: can we do modifications in the header or footer of the word template document?
@Madsycode
@Madsycode 2 года назад
have never attempted that, but I supose it should be possible!
@janisgraf5204
@janisgraf5204 4 года назад
Thanks for the nice video! How can I adjust the code so that the words in the header and footer can also be replaced?
@mahmoodtalaat3156
@mahmoodtalaat3156 3 года назад
Thanks for your efforts and very helpful video but I have a problem in editing header by this code Do you have any suggestions
@Madsycode
@Madsycode 3 года назад
not sure!!! what exactly isn't wrong
@Mrree1078
@Mrree1078 3 года назад
this is a fantastic tutorial, now how will I go about printing this directly to my printer as soon as its generated?
@allchill3470
@allchill3470 3 года назад
Sir can you add how to replace the text in word document with an image?
@GeraSimVer
@GeraSimVer 5 лет назад
Спасибо большое!!! Thank you very much!!!
@Madsycode
@Madsycode 5 лет назад
thx u ofr subscribing
@gurkanozdem5832
@gurkanozdem5832 3 года назад
How can I replace the text with a photo? @Madsycode
@patricknyirongo5005
@patricknyirongo5005 2 года назад
From 2018, I will still ask my question just incase someone the comments finds question. First thank for the code. Limitation I have is the save as function. Is there a way I can modify the code so that I can be saving with new name every time in situations that I want to create multiple word documents. E.g. Document 1, Document 2, Document 3 etc? thanks in advance.
@Madsycode
@Madsycode 2 года назад
the function saveAs could help achive that!
@EmanuelRobertoGarcia
@EmanuelRobertoGarcia 4 года назад
Great!! it works like a charm
@Madsycode
@Madsycode 4 года назад
yeah!! glad to know that!!
@wilderchui2628
@wilderchui2628 4 года назад
Hi Madsycode, thank you very much
@Madsycode
@Madsycode 4 года назад
glad to know it helped! thx for subscribing
@ElCidPhysics90
@ElCidPhysics90 3 года назад
Great video. Two questions: (1) Why call everything an object e.g. filename? Why not call it a string? Also, could you use the @"" to create a literal string without the escape characters?
@ElCidPhysics90
@ElCidPhysics90 3 года назад
NVM. Just saw that you did use the @"". lol
@Madsycode
@Madsycode 3 года назад
@@ElCidPhysics90 ok
@fatalmokrane
@fatalmokrane 3 года назад
Hi, does the template file is compiled in the .exe file ?
@darwiesh
@darwiesh 4 года назад
thx a lot great video and thx for the source code
@Madsycode
@Madsycode 4 года назад
yeah you are welcome!! thx for your sub
@nikachakvetadze8499
@nikachakvetadze8499 2 года назад
Hi there, this is realy helpfull video, but source code link does not work. can you write link correctly
@HectorSaldes
@HectorSaldes 5 лет назад
Hola, perdón si hablo español, solo tengo una pregunta, quiero guardar información en archivos de Word mediante C# y guardarla, para que después mi programa lea esa información y la muestre..... espero tu respuesta gracias.
@Madsycode
@Madsycode 5 лет назад
yo no comprende espanol am sorry man 😕could you please translate it
@HectorSaldes
@HectorSaldes 5 лет назад
Hello, sorry if I speak Spanish, I only have one question, I want to save information in Word files by C # and save it, so that after my program read that information and show it ..... I wait for your answer thanks.
@Madsycode
@Madsycode 5 лет назад
​@@HectorSaldes all you need to do ist to set the wordApp.visible = true🖕 in you code
@why-fu5979
@why-fu5979 2 года назад
how to save with a different name so that the file is not replaced?
@why-fu5979
@why-fu5979 2 года назад
did you know when creating the .doc.. there was a NullReferenceException error. and file not found. Previously the program worked fine.
@mikkelandersen6448
@mikkelandersen6448 2 года назад
I have the same problem, is there a fix?
@why-fu5979
@why-fu5979 2 года назад
@@mikkelandersen6448 I've fixed it. make sure the storage area matches the code
@mikkelandersen6448
@mikkelandersen6448 2 года назад
@@why-fu5979 everything has worked, suddenly it just broke, even if I download the code from scratch again, it still not working… Could there be an reference or something i’m missing suddenly?
@why-fu5979
@why-fu5979 2 года назад
@@mikkelandersen6448 that's right, sa I just remembered I experienced the same thing. I removed all visual studio and dotnet apps. and reinstall.
@mikkelandersen6448
@mikkelandersen6448 2 года назад
@@why-fu5979 I will try reinstalling visual studio, thanks for helping👌🏻🙌🏼
@ryanjade2836
@ryanjade2836 4 года назад
I used this tutorial to help me create (N) number of files for shareholder reports. I am noticing that it runs very slow. It takes 3 min to create only 26 files. The datatable populates almost instantly with results of the stored procedure but the actual creating of each file takes a lot of time. Is there any way to improve speed? There could be instances where we need to create 1000 customized reports. Thank you for this tutorial and thank you in advance for your help with my question.
@Madsycode
@Madsycode 4 года назад
you could use multithreats to create file while
@Yda93
@Yda93 4 года назад
Any way to save with file dialog? enable the user to select the path?
@Madsycode
@Madsycode 4 года назад
so you want n know how to save files !??
@CemKutluer
@CemKutluer 2 года назад
I tried at different PCs' and their words from 1) LTSC Professional Plus 2021 2) Word 2007 tried both docx and doc format 4 times, the error is same at wordApp.Selection.Find.Execute() function System.Runtime.InteropServices.COMException: Type mismatch 0x80020005 (DISP_E_TYPEMISMATCH) any solution or opinion that may help me?
@Madsycode
@Madsycode 2 года назад
Man I can help dind't have that problem!! maybe the issue might be the version of .Net u r using but am not sure!
@CemKutluer
@CemKutluer 2 года назад
@@Madsycode Wow man, thank you. You're still replying after 4 years. Anyway, I couldn't find a decent solution for that and used a nuget called "Spire". It was enough for me.
@Madsycode
@Madsycode 2 года назад
@@CemKutluer glad to know u found ur wat :)
@ewertoncunha5513
@ewertoncunha5513 4 года назад
how can i use c# to change text box in word?
@baronobeefdip2
@baronobeefdip2 5 лет назад
Hey there, I am trying to run this on a contract document that I didn't make, but am trying to make a program that generates contracts based on this document as a template. For some reason it's not replacing everything, among the things that refuse to change are the title and subtitle on the cover page, and some lines in a footer which is inside of a shape or a textbox of some sort. Why are these instances refusing to change with the search replace?
@Madsycode
@Madsycode 5 лет назад
for those kind of component you need specify the id
@Madsycode
@Madsycode 5 лет назад
but thats another stuff
@OnThiChungChiTinHocQuocG-xq1op
@OnThiChungChiTinHocQuocG-xq1op 4 года назад
Thanks, Save my time :)
@Madsycode
@Madsycode 4 года назад
you are welcome!! am happy for you
@yakupbakr3687
@yakupbakr3687 4 года назад
I wonder, how we can use 2 or more forms to change the word template like you did.
@Madsycode
@Madsycode 4 года назад
what do you mean exactly!!! you mean create more field or a seperate form "?
@yakupbakr3687
@yakupbakr3687 4 года назад
@@Madsycode I want to explain through on your work. I want to prepare 3 form. In the firs form, it will have only the name textbox, in the second form, only the surname textbox and in the 3rd form only the date of birth textbox. In the 3rd form, there is also a generate button like yo did. when I click on generate button, it will run the template your certiface document completely. Thank you so much.
@hiddenfreezing
@hiddenfreezing 4 года назад
Thank you very much!
@Madsycode
@Madsycode 4 года назад
you are welcome!! thx for your sub
@СвинкаЯрослав
@СвинкаЯрослав 4 года назад
Заебись, спасибо
@marcogiglio2374
@marcogiglio2374 Год назад
Where can I found source?
@khoinguyen-im1kp
@khoinguyen-im1kp 4 года назад
Is there any way to avoid the fixed pathway of the file, because the template file location is not always C:\xxx
@Madsycode
@Madsycode 4 года назад
yes of cause! or it will not be any program out there with diffrent path
@richaud266
@richaud266 4 года назад
Madsycode can do share an example. And it'd great if you can make a video about flexible path file
@Madsycode
@Madsycode 4 года назад
@@richaud266 check this docs.microsoft.com/de-de/dotnet/api/system.io.path.getrelativepath?view=netcore-3.1
@allaure0917
@allaure0917 5 лет назад
After I generated the .docx it wont let me see anything, I can open it but its just blank, not plain worksheet but plain word application nothing inside. Any suggestions?
@Madsycode
@Madsycode 5 лет назад
Did u try with my own code in the description
@mohammededderkaoui4343
@mohammededderkaoui4343 4 года назад
thank you but I want to direct print this document without open file and print
@abraofrancisco7198
@abraofrancisco7198 6 лет назад
Hi can you please assist with the error. Severity Code Description Project File Line Suppression State Error CS1061 'CriarNovo' does not contain a definition for 'FindAndReplace' and no extension method 'FindAndReplace' accepting a first argument of type '
@Madsycode
@Madsycode 6 лет назад
Hi check the case sensitivity and be sure that the function prototype is the same :)
@Nelelson
@Nelelson 2 года назад
thanks. how to save files !??
@akilarasanvinayagam5548
@akilarasanvinayagam5548 4 года назад
I got a warning saying "Could not resolve this reference. Could not locate the assembly "Bunifu_UI_v1.52". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.'' and "The referenced component 'Bunifu_UI_v1.52' could not be found." and when i run it go to else loop and pop up say "File not Found!" do anyone know why?
@Madsycode
@Madsycode 4 года назад
you need to include reference to bunifu
@akilarasanvinayagam5548
@akilarasanvinayagam5548 4 года назад
@@Madsycode It worked after I deleted the print button thank you. your video are very helpful. and Just a friendly feedback try to sound little more enthusiastic. with such great content, you channel will shine on RU-vid
@Madsycode
@Madsycode 4 года назад
@@akilarasanvinayagam5548 thx am taking notes!
@stevenshih5345
@stevenshih5345 5 лет назад
thank you man its helpful
@Madsycode
@Madsycode 5 лет назад
glad to know that!!!! th!!! and thx for subscribing
@frankfernandez1957
@frankfernandez1957 4 года назад
Amazing Video, thank you so much. it is worth noticing however than this will work with .Net framework. I tried it in .Net Core and it didn't work since the package is not compatible with this version of .Net
@Madsycode
@Madsycode 4 года назад
thx for the info!!
@nameisntimportant749
@nameisntimportant749 2 года назад
Not true. I manageed to make it work on .Net Core
@XenonOficial
@XenonOficial 5 лет назад
THANKS A LOT MAN !
@Madsycode
@Madsycode 5 лет назад
u r wellcome and thx for subscribing it mean alot for me
@infinitebai
@infinitebai 6 лет назад
Hi Madsycode, thank you for this reference, but i seem to have issues with the function SaveAs2 i'm getting an error. thanks man
@Madsycode
@Madsycode 6 лет назад
u r welcome and thx for subscribing
@Madsycode
@Madsycode 6 лет назад
but what kind of error are u getting !??
@mouadelmouzounelidrissi4489
@mouadelmouzounelidrissi4489 5 лет назад
Hi Toki Macu , Did you get a answer for your error of SaveAs2 ? i Think i can help
@Madsycode
@Madsycode 5 лет назад
let me know of you can !!!! thx for subscribing
@mikkelandersen6448
@mikkelandersen6448 2 года назад
@@mouadelmouzounelidrissi4489 Would love some help if you have an idea what could be wrong...
@halil.yanikk
@halil.yanikk 4 года назад
valla helal olsun reis :)
@aminebentayeb1404
@aminebentayeb1404 4 года назад
probleme after execute they write to me temp.docx blocked editing from user and probleme throw in saveAs2.... help me pleas
@leonardopedrosa1895
@leonardopedrosa1895 4 года назад
use close() in object before saveAs()
@Madsycode
@Madsycode 4 года назад
thx!!
@hamzasouiri1528
@hamzasouiri1528 5 лет назад
Can you please share the source code i couldn't find it in the comments
@arvinjamesmalubay9659
@arvinjamesmalubay9659 8 месяцев назад
can you please upload the source code again please
@bullet9670
@bullet9670 6 лет назад
hi i cant declare a using word = microsoft.OFFICE.interop.wordç the OFFICE there is no OFFICE in my declaration
@Madsycode
@Madsycode 6 лет назад
word = Microsoft.Office.Interop.Word
@Madsycode
@Madsycode 6 лет назад
you need to check all upper- and lowercase letters. it's case sensitiv
@Gusstaavo1
@Gusstaavo1 5 лет назад
Great!
@Madsycode
@Madsycode 5 лет назад
thx for your subscribe!!
@microsecure2612
@microsecure2612 6 лет назад
do you have the same video but to excel ?
@Madsycode
@Madsycode 6 лет назад
not now but i can peek up on that
@Madsycode
@Madsycode 6 лет назад
thx for subscribing 🙂
@microsecure2612
@microsecure2612 6 лет назад
yes pls if you can , many thanks
@robinfehrecke3112
@robinfehrecke3112 3 года назад
Super Video! Wie kann ich den Button alle ersetzen nutzen? Ich habe einen Suchtext im Dokument und einen im Header. Alles was ich bisher im Netz gefunden habe, funktioniert nicht. Es wird immer nur der Text im Dokument geändert. Wenn ich im Word Dokument das manuell anwende, werden aber alle Suchtexte geändert. Theoretisch sollte es ja mit der Funktion hier gehen: docs.microsoft.com/de-de/visualstudio/vsto/how-to-programmatically-search-for-and-replace-text-in-documents?view=vs-2019
@KYLE-uj9us
@KYLE-uj9us 3 года назад
Hi. Do you have asp.net version of this?
@Madsycode
@Madsycode 3 года назад
no sorry
@chinnavenkatarajununi1586
@chinnavenkatarajununi1586 3 года назад
i am facing "String parameter too long." error
@Madsycode
@Madsycode 3 года назад
not sure can it be that your string ist just allocating too much memory ?
@halil.yanikk
@halil.yanikk 4 года назад
word dosyasındaki resmi nasıl değiştireceğim bana yardım eder misin
@hasanmohiuddinahmed6614
@hasanmohiuddinahmed6614 4 года назад
Awesome stuff. Keep it up! Thank you so much. Can you make a tutorial on how to set continuous Line Numbers in an existing word document using Microsoft.Office.Interop.Word ? I am in search of this kindly help me in this regard I'll be very thankful to you.
@jesusjasso1510
@jesusjasso1510 5 лет назад
@Madsycode
@Madsycode 5 лет назад
thx for subscribing ☺
@markcediegabinete2647
@markcediegabinete2647 5 лет назад
Thanks bro.
@Madsycode
@Madsycode 5 лет назад
u r welcome thx for subscribing
@VPunko
@VPunko 4 года назад
Thank you for this tutorial please I want the documentation
@bekapochitev8144
@bekapochitev8144 4 года назад
on .net core 3.1 please, MVC
@Madsycode
@Madsycode 6 лет назад
got it!!! :)
@leonardopedrosa1895
@leonardopedrosa1895 4 года назад
does not work for microsoft365
@Madsycode
@Madsycode 4 года назад
ok good to know! I think its because the file system ist different
@baraawaleed6753
@baraawaleed6753 6 лет назад
thank you , but can u please send me the code source if you may please
@Madsycode
@Madsycode 6 лет назад
check the commen below someone allready pull it
@baraawaleed6753
@baraawaleed6753 6 лет назад
Thank u
@Madsycode
@Madsycode 6 лет назад
ur welcome and thank u for subscribing :)
@baraawaleed6753
@baraawaleed6753 6 лет назад
The honor is mine my friend .. but try to make your projects with code source so the viewers can download it .. just a suggestion
@coders4freedom
@coders4freedom 6 лет назад
any way that you hare the source code please?
@Madsycode
@Madsycode 6 лет назад
check the comment of #Abdulhamit KOŞKULU he allready hare it as comment :)
@Higherself999
@Higherself999 6 лет назад
what if i want to replace the data from datagridview?
@Madsycode
@Madsycode 6 лет назад
Hi #Raed all you need is to get all data from the datagrid as string
@Madsycode
@Madsycode 6 лет назад
value = row.Cells["Column"].Value.ToString();
@mouadelmouzounelidrissi4489
@mouadelmouzounelidrissi4489 5 лет назад
Please can u give us the methodes code
@Madsycode
@Madsycode 5 лет назад
the link on the description
@thegioi2531
@thegioi2531 5 лет назад
Textbox ok but picture don't
@Madsycode
@Madsycode 5 лет назад
am not quite sure, I get what u r talking about !!
@thegioi2531
@thegioi2531 5 лет назад
@@Madsycode this.FindAndReplace(wordApp, "picture", picturebox.image); No get picture to word
@thegioi2531
@thegioi2531 5 лет назад
I talk english not good
@thegioi2531
@thegioi2531 5 лет назад
Please help me
@paddy7154
@paddy7154 5 лет назад
Hey i can't find the reference :c
@Madsycode
@Madsycode 5 лет назад
what reference !??
@paddy7154
@paddy7154 5 лет назад
@@Madsycode The word reference. But now i got it ^^ i dont had office installed :D
@Madsycode
@Madsycode 5 лет назад
great thx !!! & for you subscribe👍
@fernandotrovao4093
@fernandotrovao4093 2 года назад
rubbish
Далее
The Tri Folding Phone Impressions!
11:18
Просмотров 3,1 млн
Меня знают уже все соседи😅
00:34
Comparing Microsoft Office VSTO and Web add-ins
17:34
Create Word Addins with VS 2019 in C#
19:36
Просмотров 2,8 тыс.
Debugging C# Code in Visual Studio | Mosh
31:42
Просмотров 378 тыс.
Creating Excel Files in C#
55:42
Просмотров 128 тыс.