|
From: Martin.Camitz on 1 Apr 2006 08:15 There really is no documentation worth the name for this interop capabilities in visual c++. Any samples you may come across are either vb or c#. I'd like to know how to do this ThisApplication.ActiveWorkbook.SaveAs(@"C:\MyWorkbook.xml", Excel.XlFileFormat.xlXMLSpreadsheet, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Excel.XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); in c++. I've got everything else working. I just want to save the damn thing. Thanks. Martin
From: Simon Trew on 3 Apr 2006 04:44 What framework are you using (e.g. ATL, etc)? Show us a little code from the "everything else" that you've got working, so that we can put the answer in context.
From: Martin.Camitz on 3 Apr 2006 10:47 Simon Trew skrev: > What framework are you using (e.g. ATL, etc)? > > Show us a little code from the "everything else" that you've got working, so > that we can put the answer in context. Sure. .NET I guess. It's the last commented line the doesn't work. Another issue has arisen. You can find a line in there that represents my latest of a long line of attempts at writing a doulbe into a cell. I'm using a Swedish version of excel where we like decimal commas instead of periods. No matter what I do the result will contain a period. Thank you! Martin Interop::Excel::Application* ExcelObj; // Initialize the Windows Components ExcelObj = new Excel::ApplicationClass(); // See if the Excel Application Object was successfully constructed if (!ExcelObj) { Console::WriteLine(S"Cannot start excel application."); Console::ReadLine(); return 0; } ExcelObj->Visible = true; Excel::Workbooks* theWorkbooks = ExcelObj->get_Workbooks(); if (!File::Exists(EXCEL_ANALYSIS_FILENAME)) { Console::WriteLine(S"Cannot open excel document."); Console::ReadLine(); return 0; } //Need to get the application directory! Excel::Workbook* theWorkbook = theWorkbooks->Open(/*EXCEL_ANALYSIS_FILENAME*/S"C:\\Documents and Settings\\Martin camitz\\My Documents\\micropox_gui\\output\\data_analysis.xls", __box(0), __box(true), __box(5), S"", S"", __box(true), __box(Excel::XlPlatform::xlWindows), S"\t", __box(false), __box(false), __box(0), __box(true)); ExcelObj->Calculation = Excel::XlCalculation::xlCalculationManual; // get the collection of sheets in the workbook Excel::Sheets* sheets = theWorkbook->get_Worksheets(); // get the first and only worksheet from the collection // of worksheets Excel::Worksheet* worksheet = dynamic_cast<Excel::Worksheet*>(sheets->get_Item(S"Sheet1")); StreamReader* tr; try { tr = new StreamReader(new FileStream(S".\\output\\sm_events.txt", FileMode::Open)); } catch (FileNotFoundException* e) {} Globalization::NumberFormatInfo* nfi_us = (new Globalization::CultureInfo(S"en-US", false))->NumberFormat; Globalization::NumberFormatInfo* nfi_sv = (new Globalization::CultureInfo(S"sv-SE", false))->NumberFormat; int i = 1; while (tr->Peek() != -1) { String* s = tr->ReadLine(); String* vals __gc[] = s->Split((S" \t,;")->ToCharArray()); if(String::Compare(vals[0], S"--") != 0) { Object* mixed_vals __gc[] = __gc new Object*[10]; int j = 0; mixed_vals[j] = __box(Convert::ToInt32(vals[j])); j++; mixed_vals[j] = vals[j]; j++; mixed_vals[j] = String::Format(S"={0}",__box(Convert::ToDouble(vals[j],nfi_us))->ToString(nfi_sv)); j++; mixed_vals[j] = __box(Convert::ToInt32(vals[j])); j++; mixed_vals[j] = __box(Convert::ToInt32(vals[j])); j++; mixed_vals[j] = __box(Convert::ToInt32(vals[j])); j++; mixed_vals[j] = __box(Convert::ToInt32(vals[j])); j++; mixed_vals[j] = __box(Convert::ToInt32(vals[j])); j++; mixed_vals[j] = __box(Convert::ToInt32(vals[j])); j++; Excel::Range* range = worksheet->get_Range(String::Format(S"A{0}",__box(i)),String::Format(S"J{0}",__box(i))); range->Cells->set_Value2(vals); Object* formulas __gc[] = __gc new Object*[5]; formulas[0] = String::Format(S"=1+L{0}", __box(i-1)); formulas[1] = __box(0); formulas[2] = String::Format(S"=IF(ISBLANK(L{0});N{1};L{0})",__box(i),__box(i-1)); formulas[3] = String::Format(S"=IF(L{0}=0;K{0};O{1})", __box(i), __box(i-1)); formulas[4] = String::Format(S"=IF(L{0}=0;L{1};\" \")", __box(i+1), __box(i)); range = worksheet->get_Range(String::Format(S"L{0}",__box(i)),String::Format(S"P{0}",__box(i))); range->Cells->set_Value2(formulas); } else { Excel::Range* range = worksheet->get_Range(String::Format(S"A{0}",__box(i)),String::Format(S"A{0}",__box(i))); range->Cells->set_Value(s); range = worksheet->get_Range(String::Format(S"K{0}",__box(i)),String::Format(S"K{0}",__box(i))); range->Cells->set_Value2(vals[4]); } i++; } ExcelObj->Calculate(); tr->Close(); String* fn = EXCEL_ANALYSIS_FILENAME; fn = fn->Substring(0, fn->Length - 4); i = 0; while(File::Exists(String::Format(S"{0}{1}.xls", fn, __box(i++)))); // theWorkbook->SaveAs(String::Format(S"{0}{1}.xls", fn, __box(i++)),__box(theWorkbook->get_FileFormat()),S"",S"",__box(false),__box(false),XlSaveAsAccessMode::xlNoChange,__box(XlSaveConflictResolution::xlUserResolution),__box(false),S"",S""); return 0;
From: Martin.Camitz on 5 Apr 2006 06:51 I have discovered Type::Missing with which I have replaced all arguments except the filename and the enum. Still no luck. Martin
|
Pages: 1 Prev: Acess Violation in MSDART.dll 0xC0000005 Next: compare '-1.#IND' with 1.#INF doubles ? |