Rusha
Schrieb am:
05.03.2007 06:07
|
Hallo allerseits, ich habe folgende Frage: Ist es möglich Excel auf der jeweiligen Client Maschiene über "Regel anwenden" anzusteuern? Den Code um das excel Client seitig zu erzeugen habe ich schon. Die Frage ist nur kann ich Excel Problemlos über "Regel anwenden" von einem Angebot aus aufrufen und die korrespondierenden Daten übergeben? Gibt es Methoden im der CrmService.cs die ein weitegeben von Daten an excel oder andere Programme unterstützt? Hat jemand so etwas schon einmal gemacht? Oder einen Link für mich? Ich bin für jede Hilfe dankbar Ich arbeite mit Visual Studio 2005 und Microsoft Visual C# 2005 Der Code für den Excel Aufruf funktioniert soweit
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Text.RegularExpressions;
namespace CRM_EXCEL
{ class TestAufruf
{ public static void Main()
{ ExcelPrintOffer TestObject = new ExcelPrintOffer();
TestObject.SetUpOffer();
}
}
class ExcelPrintOffer
{ protected Excel.Application VarExcelAppplication; protected Excel._Workbook VarExcelWorkbook; protected Excel._Worksheet VarExcelSheet; protected Excel.Range VarExcelRange; // generate Offer Base Document public ExcelPrintOffer ()
{ try
{ //Start Excel and get Application object.
VarExcelAppplication = new Excel.Application();
VarExcelAppplication.Visible = true; //Open existing Workbook //VarExcelWorkbook = (Excel._Workbook)(VarExcelAppplication.Workbooks.Open(VarExcelWorkbookPath, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)); //Create a new workbook.
VarExcelWorkbook = (Excel. _Workbook)(VarExcelAppplication.Workbooks.Add(Missing.Value)); //Set active Sheet of the Woorkbook as VarExcelSheet
VarExcelSheet = (Excel. _Worksheet)VarExcelWorkbook.ActiveSheet;
} catch (Exception theException)
{ String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat(errorMessage, theException.Message);
errorMessage = String.Concat(errorMessage, " Line: ");
errorMessage = String.Concat(errorMessage, theException.Source); MessageBox.Show(errorMessage, "Error");
}
}
protected void WriteStringToSheetCell(int VarExcelSheetZeileMethodenAufruf, int VarExcelSheetSpalteMethodenAufruf, string ZellenInhaltMethodenAufruf)
{
VarExcelSheet.Cells[VarExcelSheetZeileMethodenAufruf, VarExcelSheetSpalteMethodenAufruf] = ZellenInhaltMethodenAufruf;
} //Set up the generell Layout of the offer public void SetUpOffer()
{
WriteStringToSheetCell(1, 2, "Simi system offer");
VarExcelSheet.get_Range( "B1", "B1").Font.Bold = true;
VarExcelSheet.get_Range( "B1", "B1").HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter;
VarExcelSheet.get_Range( "B1", "B1").Font.Size = 14;
WriteStringToSheetCell(4, 2, "SIMI Reality Motion Systems GmbH / Postfach 1518 / 85705 Unterschleissheim / Germany");
VarExcelSheet.get_Range( "B4", "B4").VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
//Array for the "A" vertical Column string[] AColumnWordsVertical = { "Partner", "Contact", "Quotenumber", "Revisionsnummer", "Customer", "Adress", "Fon", "Fax", "Simi project offers"};
WriteArraysTopDownToOffer(AColumnWordsVertical, 1, 4); //Format as bold, vertical alignment = center.
VarExcelSheet.get_Range( "A4", "A12").Font.Bold = true;
VarExcelSheet.get_Range( "A4", "A12").VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; //VarExcelSheet.get_Range("A4", "A12").Font.Background =;
//Array for the Row16 horizontal string[] Row16WordsHorizontal = { "Simi software", "Description", "Amount", "Product", "Price" };
WriteArraysLeftRightToOffer(Row16WordsHorizontal, 16, 1); //Format as bold, vertical alignment = center.
VarExcelSheet.get_Range( "A16", "E16").Font.Bold = true;
VarExcelSheet.get_Range( "A16", "E16").VerticalAlignment = Excel.XlVAlign.xlVAlignCenter; //Array for the Row17 horizontal string[] Row17WordsHorizontal = { "Simi hardware", "Description", "Amount", "Product", "Price" };
WriteArraysLeftRightToOffer(Row17WordsHorizontal, 17, 1); //Format as bold, vertical alignment = center.
VarExcelSheet.get_Range( "A17", "E16").Font.Bold = true;
VarExcelSheet.get_Range( "A17", "E16").VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
//Array for the Row18 horizontal string[] Row18WordsHorizontal = { "Simi project offers", "Description", "Amount", "Product", "Price" };
WriteArraysLeftRightToOffer(Row18WordsHorizontal, 18, 1); //Format as bold, vertical alignment = center.
VarExcelSheet.get_Range( "A18", "E16").Font.Bold = true;
VarExcelSheet.get_Range( "A18", "E16").VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
//Array for the Row19 horizontal string[] Row19WordsHorizontal = { "Simi service", "Description", "Amount", "Product", "Price" };
WriteArraysLeftRightToOffer(Row19WordsHorizontal, 19, 1); //Format as bold, vertical alignment = center.
VarExcelSheet.get_Range( "A19", "E16").Font.Bold = true;
VarExcelSheet.get_Range( "A19", "E16").VerticalAlignment = Excel.XlVAlign.xlVAlignCenter;
//AutoFit columns
VarExcelRange = VarExcelSheet.get_Range( "A1", "H1");
VarExcelRange.EntireColumn.AutoFit(); //Make sure Excel is visible and give the user control //of Microsoft Excel's lifetime.
VarExcelAppplication.Visible = true;
VarExcelAppplication.UserControl = true;
} //Writes stringarrays to the offer determined by array column and startingrow private void WriteArraysTopDownToOffer(String[] ArrayToReadFrom, int ColumnToRunThrough, int RowToStartWritingTo)
{ int CurrentPositionInArray = 0; int VarCurrentRow = RowToStartWritingTo; String CallerString; while (CurrentPositionInArray < ArrayToReadFrom.Length)
{
CallerString = ArrayToReadFrom[CurrentPositionInArray];
WriteStringToSheetCell(VarCurrentRow, ColumnToRunThrough, CallerString);
CurrentPositionInArray++;
VarCurrentRow++;
}
} private void WriteArraysLeftRightToOffer(String[] ArrayToReadFrom, int RowToRunThrough, int ColumnToStartWritingTo)
{ int CurrentPositionInArray = 0; int VarCurrentColumn = ColumnToStartWritingTo; String CallerString; while (CurrentPositionInArray < ArrayToReadFrom.Length)
{
CallerString = ArrayToReadFrom[CurrentPositionInArray];
WriteStringToSheetCell(RowToRunThrough, VarCurrentColumn, CallerString);
CurrentPositionInArray++;
VarCurrentColumn++;
}
}
}
}
Gruß
Rusha
|